• Status: Solved
• Priority: Medium
• Security: Public
• Views: 972

# Ranking data records using VBA

Dear Experts:

I got two columns on the active worksheet

Column A: Overall Count of Items
Column B: The respective rank where duplicate values get the same rank and with no skipping of subsequent ranks.

There is a wonderful formula in Cell B2 that achieves this feat. Courtesy by barryhoudini from EE.
=IF(A2="";"";SUMPRODUCT((A\$2:A\$16>A2)/COUNTIF(A\$2:A\$16;A\$2:A\$16&""))+1)
This  formula is then simply copied down.

Now comes my problem:

This formula is to be filled into B2 of a worksheet called 'Results' and then copied down using VBA. The range can vary, there could be just 16 data records, but there also could be hundreds of data records that should be ranked.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

I have attached a sample file for your convenience.

Regards, Andreas

Count      Rank
800           1
408           2
380           3
260           4
260           4
106           5
98           6
98           6
78           7
54           8
54           8
48           9
44         10
28         11
24         12

Ranking-data-records-using-VBA.xlsx
0
Andreas Hermle
1 Solution

Commented:
Hi,

pls try

Sub Mactro5()
LastRow = Range("A" & Cells.Rows.Count).End(xlUp).Row
Range("B2:B" & LastRow).Formula = _
"=IF(A2=" & Chr(34) & Chr(34) & "," & Chr(34) & Chr(34) & ",SUMPRODUCT((A\$2:A\$" & LastRow & ">A2)/COUNTIF(A\$2:A\$" & LastRow & ",A\$2:A\$" & LastRow & "&" & Chr(34) & Chr(34) & "))+1)"
End Sub
Regards
0

Hi Rgonzo,

I am indeed deeply impressed by your expertise.

Works like a charm. Thank you very much for your professional and swift support. I really appreciate it.

Regards, Andreas
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.