Count unique text in cell and range

Akashwani

Well-known Member
Joined
Mar 14, 2009
Messages
2,911
Hi,

I've been banging my head for 3 hours with this problem, I need saving (again!)

I need to count the number of unique words that appear in a range, there are multiple words in some cells, this is what is causing me problems.
I can count the number of unique words in a range IF there is only one word per cell using the array formula in G3.
I need to count ALL unique words in A3:A10 and have the total (7) in C3.

Excel Workbook
ABCDEFGH
1********
2List of Words*Unique count*List of Words*Count*
3Red*7*Red*7*
4Red Green Blue***Blue***
5Black White***Green***
6Black***White***
7White***Yellow***
8Blue***Pink***
9Yellow***Black***
10Yellow Pink***Red***
11****Blue***
12****Green***
13****White***
14****Yellow***
15****Pink***
16****Black***
Sheet3





Your help is eagerly awaited :)

Thanks

Ak
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,

I have found the following VBA code that will help me resolve this problem, but I would prefer a formula approach as the Workbook must be VBA free :(

Code:
Sub CreateUniqueWords()
Dim LR As Long
Dim rngData As Range
Dim rngCell As Range
Dim colWords As Collection
Dim vntWord As Variant

Application.ScreenUpdating = False
Columns("J:J").ClearContents
On Error Resume Next
LR = Range("A" & Rows.Count).End(xlUp).Row
Set colWords = New Collection
Set rngData = Range("A3:A10" & LR)

For Each rngCell In rngData.Cells
    For Each vntWord In Split(Replace(Replace(Replace(rngCell.Value, """", ""), "]", ""), "[", ""), " ")
        colWords.Add colWords.Count + 1, vntWord
        If Cells(3 + colWords(vntWord), "L") <> 1 Then
            Cells(3 + colWords(vntWord), "J").Value = vntWord
            Cells(3 + colWords(vntWord), "K") = Cells(3 + colWords(vntWord), 10) + 1
            Cells(3 + colWords(vntWord), "L") = 1
        End If
    Next
    Columns("L:L").ClearContents
Next
    
LR = Range("J" & Rows.Count).End(xlUp).Row
Range("J3:J" & LR).Sort Cells(1, 2), xlDescending
Application.ScreenUpdating = True
End Sub


Any formula ideas?

Thanks

Ak
 
Upvote 0
By the way, I bet the following...

{=SUM(IF(FREQUENCY(IF($E$3:$E$16<>"",MATCH($E$3:$E$16,$E$3:$E$16,0)),ROW($E$3:$E$16)-ROW($E$3)+1),1))}

would be faster than this:

{=SUM(IF(FREQUENCY(IF(LEN($E$3:$E$16)>0,MATCH($E$3:$E$16,$E$3:$E$16,0),""), IF(LEN($E$3:$E$16)>0,MATCH($E$3:$E$16,$E$3:$E$16,0),""))>0,1))}
 
Upvote 0
Hi Aladin,

Thanks for the reply, yep, your formula does calculate faster.
Do you (or anyone else) have any suggestions on how I could solve the original question? ;)

Thanks

Ak
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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