Count specific characters in a cell - Excel

后端 未结 4 1581
日久生厌
日久生厌 2021-02-11 03:43

I would like to count all special characters (!%_*?+-,) in a cell.

For example:

With this formula =LEN(D2)-LEN(SUBSTITUTE(D2;\"!\";\"\")) i

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-11 04:37

    Using formulas only, not VBA, this is possible with the following two approaches:

    Consider the text in A1:

    First approach:

    Multiple nested SUBSTITUTE:

    =LEN(A1)-LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,",",""),"-",""),"+",""),"?",""),"*",""),"_",""),"%",""),"!",""))
    

    Second approach:

    Using SUMPRDUKT for getting the MID function in array context to get each single charachter of the string in A1 compared with each single special character:

    =SUMPRODUCT(--(MID(A1,ROW($1:$1000),1)={"!","%","_","*","?","+","-",","}))
    

提交回复
热议问题