Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

function

excel

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?

like image 681
dwwilson66 Avatar asked Dec 20 '22 05:12

dwwilson66


2 Answers

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.

like image 94
KyleMit Avatar answered Jan 17 '23 07:01

KyleMit


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)
like image 25
pnuts Avatar answered Jan 17 '23 05:01

pnuts