A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

counting characters



 
 
Thread Tools Display Modes
  #1  
Old April 28th, 2004, 01:22 PM
KK
external usenet poster
 
Posts: n/a
Default counting characters

Hello,

I have a spreadsheet with cells containing strings of characters. eg DWDE
or WWN or ENWEE etc. Strings are not necessarily the same length but are 5
characters maximum.

I want to count the numbers of each character in each string. so for the 1st
example above I want to end up with the answer 2 for the number of Ds, 1 for
Ws, 1 for Es. For the last example I need 0 for Ds, 3 for Es, 1 for Ns, 1
for Ws etc.

I can do it using the MID function, testing the string character by
character to see if it is equal to 'D' or 'W' etc, and counting logical
'yes' values. It works OK, but it is very messy. Am I missing something more
elegant?

Thanks

KK


  #2  
Old April 28th, 2004, 01:49 PM
Bernie Deitrick
external usenet poster
 
Posts: n/a
Default counting characters

KK,

To count D's use the formula

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

HTH,
Bernie
MS Excel MVP

"KK" wrote in message
...
Hello,

I have a spreadsheet with cells containing strings of characters. eg DWDE
or WWN or ENWEE etc. Strings are not necessarily the same length but are 5
characters maximum.

I want to count the numbers of each character in each string. so for the

1st
example above I want to end up with the answer 2 for the number of Ds, 1

for
Ws, 1 for Es. For the last example I need 0 for Ds, 3 for Es, 1 for Ns, 1
for Ws etc.

I can do it using the MID function, testing the string character by
character to see if it is equal to 'D' or 'W' etc, and counting logical
'yes' values. It works OK, but it is very messy. Am I missing something

more
elegant?

Thanks

KK




  #3  
Old April 28th, 2004, 02:03 PM
BrianB
external usenet poster
 
Posts: n/a
Default counting characters

It would be possible to write a macro to do the job, but this would not
be exactly straghtforward. I guess a formula approach would do just as
well. You do not say how you want the counts shown or whether all
letters of the alphabet might be included. Also duplicate letters will
need to be dealt with. One quick method :-

Say your list is in column A.
I would use the next 5 columns to split the string into single
characters using =MID(A1,1,1) ,=MID(A1,2,1) etc.
I would then use the next 5 columns to do the count
eg. cell G1 would have the formula =COUNTIF($B1:E1,B1)

The row of formulas can then be copied down.


---
Message posted from http://www.ExcelForum.com/

  #4  
Old April 28th, 2004, 09:53 PM
David McRitchie
external usenet poster
 
Posts: n/a
Default counting characters

Missed that question was already answered but note
that SUBSTITUTE is case sensitive.

A1: DWDE
E1: =LEN(A1)-LEN(SUBSTITUTE(A1,"D",""))
F1: =LEN($A1)-LEN(SUBSTITUTE($A1,"E",""))

Substitute is case sensitive, you could use
E1: =LEN(A1)-LEN(SUBSTITUTE(UPPER(A1),"D",""))
to make it case insensitive.

More of similar things on my strings.htm web page.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"KK" wrote in message ...
Hello,

I have a spreadsheet with cells containing strings of characters. eg DWDE
or WWN or ENWEE etc. Strings are not necessarily the same length but are 5
characters maximum.

I want to count the numbers of each character in each string. so for the 1st
example above I want to end up with the answer 2 for the number of Ds, 1 for
Ws, 1 for Es. For the last example I need 0 for Ds, 3 for Es, 1 for Ns, 1
for Ws etc.

I can do it using the MID function, testing the string character by
character to see if it is equal to 'D' or 'W' etc, and counting logical
'yes' values. It works OK, but it is very messy. Am I missing something more
elegant?

Thanks

KK





  #5  
Old April 29th, 2004, 12:59 PM
KK
external usenet poster
 
Posts: n/a
Default Thanks (counting characters)

Thanks for the help, this looks a lot simpler.

Deep respect.

KK


"KK" wrote in message
...
Hello,

I have a spreadsheet with cells containing strings of characters. eg DWDE
or WWN or ENWEE etc. Strings are not necessarily the same length but are 5
characters maximum.

I want to count the numbers of each character in each string. so for the

1st
example above I want to end up with the answer 2 for the number of Ds, 1

for
Ws, 1 for Es. For the last example I need 0 for Ds, 3 for Es, 1 for Ns, 1
for Ws etc.

I can do it using the MID function, testing the string character by
character to see if it is equal to 'D' or 'W' etc, and counting logical
'yes' values. It works OK, but it is very messy. Am I missing something

more
elegant?

Thanks

KK




  #6  
Old April 30th, 2004, 02:03 AM
TKT-Tang
external usenet poster
 
Posts: n/a
Default Thanks (counting characters)

1. Enter "ENWEE" inti cell A1.
2. Enter the following formula into cell A2 :-
=LEN(A1)-LEN(SUBSTITUTE(A1,"E",""))
3. The formula returns the number of E's.

Regards.
  #7  
Old April 30th, 2004, 04:20 AM
Peo Sjoblom
external usenet poster
 
Posts: n/a
Default Thanks (counting characters)

You (and anyone else) would probably benefit if you got a newsreader instead
of using
Google for posting. This post was already answered by several people over 36
hours ago!

--

Regards,

Peo Sjoblom

"TKT-Tang" wrote in message
om...
1. Enter "ENWEE" inti cell A1.
2. Enter the following formula into cell A2 :-
=LEN(A1)-LEN(SUBSTITUTE(A1,"E",""))
3. The formula returns the number of E's.

Regards.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:27 PM.


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