VBA to Sort data based on Columnn. Anybody Please ?

Ombir

Active Member
Joined
Oct 1, 2015
Messages
433
Hi friends,

I have below data which is need to sort on based of Question Serial No in Row 1.


ABCDEFGHIJKLMNOPQ
1RollQuestion Serial No123456789101112131415
21001Master's Question Number815364791110141513122
3ResultCWWWWCWWWWWWWWW
4Score100001000000000
51002Master's Question Number141213125415711938610
6ResultCWWCWWCWWWWWWCW
7Score100100100000010
81003Master's Question Number142515671310111438912
9ResultWWWWWCWWWWWWWWW
10Score000001000000000

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1






Each record consists of 3 rows. Master Question Number, Result and Score. I want to sort Master Question Number row for each Rollno on same order as Top row Column C:Q. Remaining 2 rows for each rollno have to be shifted as per Master Question Number row.

Can anybody provide some VBA code to sort this. Thank you.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:
Code:
Sub Macro1()

Dim x       As Long
Dim LR      As Long

    Application.ScreenUpdating = False
        
    With Sheets("Sheet1")
        LR = .Cells(.rows.count, 3).End(xlUp).row
    
        For x = 2 To LR Step 3
            .Cells(x, 3).Resize(3, .Range("Q1").Column - 2).Sort key1:=.Cells(x, 3), order1:=xlAscending, Orientation:=xlLeftToRight
        Next x
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,673
Members
449,178
Latest member
Emilou

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