Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob
 
Posts: n/a
Default Finding/counting a given character within a cell

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
hans bal(nl)
 
Posts: n/a
Default Finding/counting a given character within a cell

You can use this user-defined function:

Function CountChar(MyChar, Mystring)
Dim counter As Integer

CountChar = 0

For counter = 1 To Len(Mystring)
If Mid(Mystring, counter, 1) = MyChar Then CountChar = CountChar + 1
Next counter

End Function


Go to tools-macro-visual basic editor and enter the text above.

You can then use this function like this :

=countchar("a",B1)

( assuming the cell you want to evaluate is B1)


HTH


"Bob" wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob
 
Posts: n/a
Default Finding/counting a given character within a cell

Hans,
Your user-defined function did the trick! Thanks a million!
Regards, Bob

"hans bal(nl)" wrote:

You can use this user-defined function:

Function CountChar(MyChar, Mystring)
Dim counter As Integer

CountChar = 0

For counter = 1 To Len(Mystring)
If Mid(Mystring, counter, 1) = MyChar Then CountChar = CountChar + 1
Next counter

End Function


Go to tools-macro-visual basic editor and enter the text above.

You can then use this function like this :

=countchar("a",B1)

( assuming the cell you want to evaluate is B1)


HTH


"Bob" wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default Finding/counting a given character within a cell

=(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),lower("a"),"")))/LEN("a")
Will count the number of A's or a's in A1.

If you want just the lower case a's:
=(LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))/LEN("a")



Bob wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bearacade
 
Posts: n/a
Default Finding/counting a given character within a cell


Try this

=LEN(A1)-LEN(SUBSTITUTE(A1,"e",""))


--
Bearacade


------------------------------------------------------------------------
Bearacade's Profile: http://www.excelforum.com/member.php...o&userid=35016
View this thread: http://www.excelforum.com/showthread...hreadid=549007



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob
 
Posts: n/a
Default Finding/counting a given character within a cell

Dave,
Thanks for your solution and your help! I am always amazed at the power of
the SUBSTITUTE function.
Regards, Bob

"Dave Peterson" wrote:

=(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),lower("a"),"")))/LEN("a")
Will count the number of A's or a's in A1.

If you want just the lower case a's:
=(LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))/LEN("a")



Bob wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bob
 
Posts: n/a
Default Finding/counting a given character within a cell

Bearacade,
Thanks for your help! I sincerely appreciate it.
Regards, Bob


"Bearacade" wrote:


Try this

=LEN(A1)-LEN(SUBSTITUTE(A1,"e",""))


--
Bearacade


------------------------------------------------------------------------
Bearacade's Profile: http://www.excelforum.com/member.php...o&userid=35016
View this thread: http://www.excelforum.com/showthread...hreadid=549007


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default Finding/counting a given character within a cell

I should have included that =substitute() is case sensitive. That's why I
included two versions.



Bob wrote:

Dave,
Thanks for your solution and your help! I am always amazed at the power of
the SUBSTITUTE function.
Regards, Bob

"Dave Peterson" wrote:

=(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),lower("a"),"")))/LEN("a")
Will count the number of A's or a's in A1.

If you want just the lower case a's:
=(LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))/LEN("a")



Bob wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.


--

Dave Peterson


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
David Biddulph
 
Posts: n/a
Default Finding/counting a given character within a cell

"Dave Peterson" wrote in message
...

Bob wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.


=(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),lower("a"),"")))/LEN("a")
Will count the number of A's or a's in A1.

If you want just the lower case a's:
=(LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))/LEN("a")


What is the division by LEN("a") doing? Isn't LEN("a") equal to 1?
--
David Biddulph


  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Kevin Vaughn
 
Posts: n/a
Default Finding/counting a given character within a cell

I think you're right. It looks like the /1 is not needed.

--
Kevin Vaughn


"David Biddulph" wrote:

"Dave Peterson" wrote in message
...

Bob wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.


=(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),lower("a"),"")))/LEN("a")
Will count the number of A's or a's in A1.

If you want just the lower case a's:
=(LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))/LEN("a")


What is the division by LEN("a") doing? Isn't LEN("a") equal to 1?
--
David Biddulph





  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default Finding/counting a given character within a cell

Yep.

But anyone who uses google may want to find the number of times "David" appears
in a cell.

Then the formula is easily changed--it's kind of self documenting.



David Biddulph wrote:

"Dave Peterson" wrote in message
...

Bob wrote:

For a given cell, I need to count the number of times a given character
(e.g., the letter "a") appears. Is there a worksheet function or formula
that will help me do this? Thanks for any help.


=(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),lower("a"),"")))/LEN("a")
Will count the number of A's or a's in A1.

If you want just the lower case a's:
=(LEN(A1)-LEN(SUBSTITUTE(A1,"a","")))/LEN("a")


What is the division by LEN("a") doing? Isn't LEN("a") equal to 1?
--
David Biddulph


--

Dave Peterson
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
Compiling macro based on cell values simonsmith Excel Discussion (Misc queries) 1 May 16th 06 08:31 PM
Custom functions calculating time arguments Help Desperate Bill_De Excel Worksheet Functions 12 April 25th 06 02:22 AM
Possible Lookup Table Karen Excel Worksheet Functions 5 June 8th 05 09:43 PM
Cell 255 character limit and formula EaglesNest Excel Worksheet Functions 6 February 27th 05 12:06 AM
Searching a cell for a certain character. Matt Excel Worksheet Functions 3 January 3rd 05 09:14 PM


All times are GMT +1. The time now is 05:54 AM.

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"