counting unique words in a CELL, separated by "_"

kimyee

New Member
Joined
May 2, 2011
Messages
7
Hello,

I am trying to find a formula to count the unique values in a cell and some of the unique values contain spaces within them; the ending of each value is indicated by an underscore. The data looks something like this (A# denotes column-row):

A1 T2_T2_T2_T2_
A2 T3_T3_T3SE B_T3SE B_
A3 T3_T3_T3SE B_T3SE B_
A4 T3_T3_T3SE B_T3SE B_
A5 T3_T3_T3SE B_T3SE B_
A6 T3_T3_T3SE B_T3SE B_
A7 T3_T3_T3SE B_T3SE B_
A8 T3_T3_T3SE B_T3SE B_
A9 T3_T3_T3SE B_T3SE B_
A10 T3_T3_T3SE B_T3SE B_
A11 T3_T3_T3SE B_T3SE B_
A12 T3_T3_T3SE B_T3SE B_
A13 T3_T3_T3SE B_T3SE B_
A14 T3_T3_T3SE B_T3SE B_
A15 T3_T2_T2_T3

Column B will return the number of unique values. So B1=1, B2=2, B3=2, etc.

How can you count unique values within a CELL, rather than in a range? These values are concatenated, so it is no problem changing the underscore to another symbol/value.

Thanks very much,
Kim
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hello,

I am trying to find a formula to count the unique values in a cell and some of the unique values contain spaces within them; the ending of each value is indicated by an underscore. The data looks something like this (A# denotes column-row):

A1 T2_T2_T2_T2_
A2 T3_T3_T3SE B_T3SE B_
A3 T3_T3_T3SE B_T3SE B_
A4 T3_T3_T3SE B_T3SE B_
A5 T3_T3_T3SE B_T3SE B_
A6 T3_T3_T3SE B_T3SE B_
A7 T3_T3_T3SE B_T3SE B_
A8 T3_T3_T3SE B_T3SE B_
A9 T3_T3_T3SE B_T3SE B_
A10 T3_T3_T3SE B_T3SE B_
A11 T3_T3_T3SE B_T3SE B_
A12 T3_T3_T3SE B_T3SE B_
A13 T3_T3_T3SE B_T3SE B_
A14 T3_T3_T3SE B_T3SE B_
A15 T3_T2_T2_T3

Column B will return the number of unique values. So B1=1, B2=2, B3=2, etc.

How can you count unique values within a CELL, rather than in a range? These values are concatenated, so it is no problem changing the underscore to another symbol/value.

Thanks very much,
Kim
If you can place each item in its own cell then it would be fairly easy.

It's pretty easy to place each item in its own cell if there's a common delimiter or common item length.

Check out Text to Columns.
 
Upvote 0
Thanks for the suggestion. The values were actually originally from a range, but concatenated--each string separated by the "_" is a concatenation of 8 columns across each row. So alternately, is it possible to ask Excel to "find the number of unique values in the range A:H among A:B,C:D,E:F,G:H?"

Thanks, Kim
 
Upvote 0
The examples you have given all look as if they are similar length (with a couple of exceptions).

Can you give us 2 or 3 DIFFERENT examples, and explain what the results should be for each one ?

It sounds as if counting the underscore characters in the string might be (part of) a solution, and this is fairly easy to do.
 
Upvote 0
This essentially counts the spaces + 1

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

To account for the possiblity of double spaces, or leading/trailing spaces

=LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+1


Hope that helps.
 
Upvote 0
Thanks for the suggestion. The values were actually originally from a range, but concatenated--each string separated by the "_" is a concatenation of 8 columns across each row. So alternately, is it possible to ask Excel to "find the number of unique values in the range A:H among A:B,C:D,E:F,G:H?"

Thanks, Kim
See if this helps...

Book1
ABCDE
1____Uniques
2XXYZ3
3ABCD4
4ABBB2
5XXXX1
Sheet3

Formula entered in E2 and copied down:

=SUMPRODUCT(1/COUNTIF(A2:D2,A2:D2))
 
Upvote 0
Hi Biff, Gerald, Jonmo1,

Thanks for the suggestions. Jonmo1, thanks for the equation: I'm actually familiar with that one and it is certainly useful for counting; for this question I was also interested in counting just the unique values. Gerald and Biff, per your feedback I took the commonsense route and text-to-columned the string, delimited by "_". Gerald, your equation worked perfectly for counting the unique values among the four columns.

Thank you for your prompt help!

Kim
 
Upvote 0
Hi Biff, Gerald, Jonmo1,

Thanks for the suggestions. Jonmo1, thanks for the equation: I'm actually familiar with that one and it is certainly useful for counting; for this question I was also interested in counting just the unique values. Gerald and Biff, per your feedback I took the commonsense route and text-to-columned the string, delimited by "_". Gerald, your equation worked perfectly for counting the unique values among the four columns.

Thank you for your prompt help!

Kim
Nice formula, Gerald! ;)

You're welcome! Thanks for the feedback! :cool:
 
Upvote 0
Oh no! Sorry, I meant Biff. You guys all rock though. Thanks for the help. - Kim
I was just teasing ya! :biggrin:

There are many very knowledgeable folks on this site. Hang out here and you're guaranteed to learn something!
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top