counting occurances of a char. within a text string/cell

J

Justin Ater

Can anyone recommend a easy method for programmatically determining the
number of times a character occurs within a single cell (e.g., the character
"*" occurs 5 times in text "A*B*C*D*E*F"). Thanks,

Justin
 
B

Bill Lunney

From a previous post...


Public Function GetCharCount(vString As String, CheckChar As String) as
Integer
Count=0
For n=1 to len(vstring)
If mid(vstring,n,1)=CheckChar then Count = Count + 1
Next
GetCharCount=Count
End Function


--
Regards,


Bill Lunney
www.billlunney.com
 
C

Chip Pearson

Justin,

Try something like

NumChars = Len(S) - Len(Replace(S, "*", ""))

where S is your string.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top