简体   繁体   中英

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 (eg, 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?

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.

计算逗号可能没有多大意义,因为如果您知道最多总是两个逗号,您可能会跳到:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM