# Count unique characters in a string

1. ## Count unique characters in a string

Hi all,
Does anyone know how to count the number of unique characters in a particular cell?
ie if I have "AFDED" in a cell - I would like to see the length of the string as 4 (rather than 5 - as you would get from the "len" function).

Thanks very much.

yelk  Register To Reply

2. I'll be interested to see if someone can come up with a better solution, but this is what I drew up after reading the question...presuming the value to be examined is in cell A1:

=SUM(IF((LEN(A1)-LEN(SUBSTITUTE(A1,{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","1","2","3","4","5","6","7","8","9","0"},""))),1,0))

The advantage of the above is you can be specific about characters to count....for example, the above ignores spaces.

I'm sure there are other ways to do this, but maybe this will work just fine.  Register To Reply

3. This formula will count 1 instance of any character, spaces, punctuation letters etc. It's case-sensitive so although

AFDED

will give a count of 4

AbB %Yy = 7

BBB 6 =3

=COUNT(1/FREQUENCY(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1)),ROW(INDIRECT("1:255"))))

confirmed with CTRL+SHIFT+ENTER  Register To Reply

4. or amending Lotus123's approach

=SUM(IF((LEN(A1)-LEN(SUBSTITUTE(A1,CHAR(ROW(INDIRECT("1:255"))),""))),1,0))

also confirmed with CTRL+SHIFT+ENTER  Register To Reply