PDA

View Full Version : [SOLVED:] Sort each subset of n rows by specific column ranking



RINCONPAUL
07-21-2017, 06:16 PM
I'm after macro code to sort each 5 rows of data in cols A:D by the rank assigned in col C until reaching a blank row. The resultant sort required is shown alongside in cols F:I
Thanks

YasserKhalil
07-21-2017, 11:29 PM
Hello
If the number of each subset is fixed try that code


Sub Test()
Dim i As Long
Dim r As Range


Application.ScreenUpdating = 0
Columns("A:D").Copy Columns("F")
For i = 2 To Cells(Rows.Count, "F").End(xlUp).Row Step 5
Set r = Range("F" & i).Resize(5, 4)
r.Sort Key1:=Range("H" & i).Resize(5), Order1:=xlAscending
Next i
Application.ScreenUpdating = 1
End Sub

RINCONPAUL
07-22-2017, 12:00 AM
Thankyou so much YasserKhalil, works great! :cloud9:

YasserKhalil
07-22-2017, 12:28 AM
You're welcome. Glad I can offer some help
Regards