Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is There Excel Function to Count a Certain Character in Value 2

Status
Not open for further replies.

alex20850

Programmer
Mar 28, 2003
83
US
I have a list of codes. Some of these codes have one dash in them, others two, some with one space, some with two or more. I would like to run a function that would count how many dashes (or how many spaces) are in a code.
 



Hi,

Please post VBA code questions in Forum707.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
If you wanted a formula to tell you how many dashes were in a code then:
=LEN(A1)-LEN(SUBSTITUTE(A1,"-",""))
would do it.
Likewise, to see how many spaces were in a code, then:
=LEN(A1)-LEN(SUBSTITUTE(A1," ",""))
would do it.
To count how many spaces or dashes were in a code:
=(LEN(A1)-LEN(SUBSTITUTE(A1,"-","")))+(LEN(A1)-LEN(SUBSTITUTE(A1," ","")))

Cheers, Glenn.

Beauty is in the eye of the beerholder.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top