Code for displaying top 3 most common numbers within a sigle column

chanhh

New Member
Joined
Feb 15, 2019
Messages
4
Hi, I would like to find the top 3 most common numbers within column D using Marco and display the result on the side.
Start counting from D6 all the way till the bottom. (There could be 1000+ rows). Thank you.

Display the following on the side
1st most common : XX
2nd most common: XX
3rd most common: XX
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try this:

Code:
Sub displaying_top_3()
'
    Application.ScreenUpdating = False
    u = Range("D" & Rows.Count).End(xlUp).Row
    Range("D6:D" & u).Copy Range("E6")
    ActiveSheet.Range("E6:E" & u).RemoveDuplicates Columns:=1, Header:=xlNo
    With Range("F6:F" & Range("E" & Rows.Count).End(xlUp).Row)
        .FormulaR1C1 = "=COUNTIF(R6C4:R21C4,RC[-1])"
        .Value = .Value
    End With
    Range("E6:F" & Range("E" & Rows.Count).End(xlUp).Row).Sort key1:=Range("F6"), order1:=xlDescending, Header:=xlNo
    Range("E9:F" & Range("E" & Rows.Count).End(xlUp).Row).Clear
End Sub

You can also get the 3 most common with a pivot table.
 
Upvote 0
Thank you for the code DanteAmor.

However, the code is not 100% correct. I tried modifying it and I couldn't get it worked. I want the values to be displayed on cell starting at U7 (1st common), U8 (2nd Common), U9 (3rd common)

I applied filter to the column D and result is showing as follow:

- A number appears in column D only 5 times (Not 3rd common)
- 2nd common <- Yes
- 1st common <- Yes
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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