View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Keith Willshaw Keith Willshaw is offline
external usenet poster
 
Posts: 170
Default frequency of characters within a string


"Nick" wrote in message
...
I wish to to count the frequency of a character wthin a
string. Does anyone have any idea how this is possible?

My best guess so far is to create a loop using
application.worksheetfunction.find but this is rather
tedious.

Does anyone know if there is a function which will do it
for me? I have spent ages in the help files but cant find
much.

I know application.worksheetfunction.frequency is similar
to what I want but it needs an array entered into it
whilst I need to input cells(x, y).value

Any help would be much appreciated


In VBA its trivial

Public Function CountChar(myCell As Range, myChar As String) As Integer

Dim n As Integer
n = 1
CountChar = 0

While InStr(n, myCell.Text, myChar) < 0
CountChar = CountChar + 1
n = InStr(n, myCell.Text, myChar) + 1
Wend


End Function