hi!
i'm a novel programmer in vba and i am looking for a funtion or procedure
that returns the number of times that a specific character appears in a
given paragraph

I´ll put an example to explain myself better:

dim text as string
dim count as integer

text= "name * surname * age "
' XXXXX is my desired procedure:
count= XXXXX(text, *)


' this procedure must return '2', that is number of asterisks


anybody knows if there is any vba funtion to make the count? or some idea to
construct my procedure?

Re: count-if by Jezebel

Jezebel
Fri Sep 01 07:27:13 CDT 2006

Count = len(text) - len(replace(text,"*",""))




"Laura" <Laura@discussions.microsoft.com> wrote in message
news:DFA20432-83DE-4B46-8091-FFFC6DCEFE0F@microsoft.com...
> hi!
> i'm a novel programmer in vba and i am looking for a funtion or procedure
> that returns the number of times that a specific character appears in a
> given paragraph
>
> I´ll put an example to explain myself better:
>
> dim text as string
> dim count as integer
>
> text= "name * surname * age "
> ' XXXXX is my desired procedure:
> count= XXXXX(text, *)
>
>
> ' this procedure must return '2', that is number of asterisks
>
>
> anybody knows if there is any vba funtion to make the count? or some idea
> to
> construct my procedure?



Re: count-if by Greg

Greg
Fri Sep 01 07:40:53 CDT 2006

Perhaps something like this:

Sub ScratchMacro()
Dim myString As String
Dim myChar As String
myString =3D "name * surname * age"
myChar =3D Asc("*")
MsgBox Count(myString, myChar)
End Sub
Function Count(pString, pChar) As Long
Dim i As Long
For i =3D 1 To Len(pString)
If Asc(Mid(pString, i, 1)) =3D pChar Then
Count =3D Count + 1
End If
Next
End Function



Laura wrote:
> hi!
> i'm a novel programmer in vba and i am looking for a funtion or procedure
> that returns the number of times that a specific character appears in a
> given paragraph
>
> I=B4ll put an example to explain myself better:
>
> dim text as string
> dim count as integer
>
> text=3D "name * surname * age "
> ' XXXXX is my desired procedure:
> count=3D XXXXX(text, *)
>
>
> ' this procedure must return '2', that is number of asterisks
>
>
> anybody knows if there is any vba funtion to make the count? or some idea=
to
> construct my procedure?


Re: count-if by Greg

Greg
Fri Sep 01 07:41:57 CDT 2006

Yes that is much easier.

Jezebel wrote:
> Count =3D len(text) - len(replace(text,"*",""))
>
>
>
>
> "Laura" <Laura@discussions.microsoft.com> wrote in message
> news:DFA20432-83DE-4B46-8091-FFFC6DCEFE0F@microsoft.com...
> > hi!
> > i'm a novel programmer in vba and i am looking for a funtion or procedu=
re
> > that returns the number of times that a specific character appears in a
> > given paragraph
> >
> > I=B4ll put an example to explain myself better:
> >
> > dim text as string
> > dim count as integer
> >
> > text=3D "name * surname * age "
> > ' XXXXX is my desired procedure:
> > count=3D XXXXX(text, *)
> >
> >
> > ' this procedure must return '2', that is number of asterisks
> >
> >
> > anybody knows if there is any vba funtion to make the count? or some id=
ea
> > to
> > construct my procedure?


Re: count-if by Laura

Laura
Fri Sep 01 08:06:01 CDT 2006

thanks a lot to both!
Jezebel: i'm very impress with your idea: is simple and brilliant, is just
what i was looking for