dwwilson66
dwwilson66

Reputation: 7074

Is there an Excel function to count occurrences of a certain characters in a cell?

A client has an Excel file that needs to have some names scrubbed. In particular, we're trying to isolate suffixes on names (e.g., Jr., Sr., III, etc.) Names are ALWAYS formatted LastName, FirstName, Suffix in the cell, and I am trying to count the number of commas in a cell. If the cell has more than one comma in it, I can identify that cell as having a name suffix.

However, all of the COUNT functions in Excel count instances of CELLS, not characters within cells. Is there a function that counts occurrences of specific characters in a cell and returns that count?

Upvotes: 4

Views: 1411

Answers (2)

pnuts
pnuts

Reputation: 59495

There may not be much point in counting commas because if you know there will always be two at most you might jump to:

=IFERROR(REPLACE(A1,FIND(",",A1,FIND(" ",A1)+1),99,""),A1)

Upvotes: 1

KyleMit
KyleMit

Reputation: 30407

You can get the number of characters in the cell and then compare that to the number of characters in the cell if you substituted out all the commas with empty spaces:

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

This is also a neat way to get word counts in excel by counting the number of spaces.

Upvotes: 10

Related Questions