How can I count the number of times a phrase is repeated in a row?

gohotels

New Member
Joined
May 10, 2012
Messages
7
Hello, does anybody know how I can count the number of times each unique phrase in row "A" is repeated?

For example if my data set was

Blue
Green
Black
Green
Red
Red
Red
Red Hat

how can I get excel to count the number of times and return data like

Blue 1
Green 2
Black 1
Green 2
Red 3
Red 3
Red 3
Red Hat 1

Any help would be appreciated!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try jindon's code on a copy of your workbook

Code:
Sub test()
Dim e
With CreateObject("Scripting.Dictionary")
    For Each e In Sheets(1).Range("a2").CurrentRegion.Value
        If Not IsEmpty(e) Then .Item(e) = .Item(e) + 1
    Next
    For Each e In .keys
        If .Item(e) = 1 Then .Remove e
    Next
    Sheets(2).Cells(1).Resize(.Count, 2).Value = _
    Application.Transpose(Array(.keys, .items))
    Sheets(2).Cells(1).CurrentRegion.Columns(2) _
    .NumberFormat = "0"" Times"""
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,619
Messages
6,125,873
Members
449,267
Latest member
ajaykosuri

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