Looking for VBA Code to rank Group data

KWL

New Member
Joined
Apr 17, 2011
Messages
16
I prepare a daily spreadsheet that varies in length (up to 3000 rows)…. Column A contains defined “groups” of various lengths beginning in A2 with a blank row separator between each group…. Column P contains numeric values unique to each group…. In Column Q, I want to rank each value in Column P (from low to high) with “low” = 1.
I have been using the following formula located in P2:
=IF(ISBLANK(A2),””,1+SUMPRODUCT(($A$2:$A$3000=A2)*($P$2:$P$3000<P2)))
I copy and drag to the bottom of the sheet…. For some reason, I am getting lots of random errors?
Instead of the above, I would like to use VBA Code…. I don’t want to use the Macro recorder because of the random errors…. Can anyone help?
Thanks in advance,
KWL
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Hi,

Does this code work for you?
Code:
Sub aVBAcode()
Dim e As Range, q As Range
Application.ScreenUpdating = False
Set e = Range("A2")
Do While e.Row < Rows.Count
If e(2) = "" Then
    Set q = e.Offset(, 15)
    Set e = e.End(4)
Else
    Set q = Range(e, e.End(4)).Offset(, 15)
    Set e = e.End(4).End(4)
End If
q.Offset(, 1) = "=RANK(" & q.Address & "," & q.Address & ",1)"
Loop
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Awesome.... Works to perfection!

Thank you so very very much for the help!

Best regards,

KWL
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
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