Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default frequency of characters within a string

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default frequency of characters within a string

AFAIK there isn't a nice inbuilt function to do this. Whatever does the job
it will equate to the process you described even if it's wrapped in a
function.

I'd do something like:

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

Even if there is another of way of doing this the function takes about 2
minutes to write and the whole thing is done.


--

Regards,


Bill Lunney
www.billlunney.com

"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



  #3   Report Post  
Posted to microsoft.public.excel.programming
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default frequency of characters within a string

I didn't think that there was a function to do it.
Your function seems pretty solid.
I will be using it in the near future, thank you.


-----Original Message-----
AFAIK there isn't a nice inbuilt function to do this.

Whatever does the job
it will equate to the process you described even if it's

wrapped in a
function.

I'd do something like:

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

Even if there is another of way of doing this the

function takes about 2
minutes to write and the whole thing is done.


--

Regards,


Bill Lunney
www.billlunney.com

"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



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 576
Default frequency of characters within a string

Dave,

Good One! That's what I call thinking out of the box!

steve

"Dave" wrote in message
. au...

"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


If you want to do it in a normal function you could use a formula such as
=LEN(A1)-LEN(SUBSTITUTE(A1,"b",""))
to count the frequency of "b" characters in a string in cell A1

Cheers

Dave




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting the frequency of a text string Michael Styles Excel Discussion (Misc queries) 2 May 19th 09 07:08 PM
Insert Leading Characters If String Is Only 7 Characters Paperback Writer Excel Discussion (Misc queries) 2 April 21st 09 09:07 PM
Frequency of a word string in an excel database Danny_McCaslin Excel Discussion (Misc queries) 2 December 13th 06 06:11 PM
get characters from a string in excel Joao Excel Worksheet Functions 2 June 8th 05 09:47 AM
pulling characters out of a string Patrick Excel Worksheet Functions 3 November 12th 04 06:58 PM


All times are GMT +1. The time now is 07:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"