Good morning All,
I have a vba code that sort 60 pairs of Columns Most to least
For example :
It sort Most to Least the Column A3:A38 Based on value of Column B3, Sort next column C3:C38 Based on Values of D3:D38 and so on.. (is supposed to stop after 50 pairs of columns when find the last empty column, but is not. it's keep like looping.
The code is doing the job but it keep going and sort whatever data that is not supposed to be sorted. sometime seems that stop working but is not, (keep finding data to sort)
Please i need to Add the right snipped, can someone help me?
This is the Code
Thanks!
I have a vba code that sort 60 pairs of Columns Most to least
For example :
It sort Most to Least the Column A3:A38 Based on value of Column B3, Sort next column C3:C38 Based on Values of D3:D38 and so on.. (is supposed to stop after 50 pairs of columns when find the last empty column, but is not. it's keep like looping.
The code is doing the job but it keep going and sort whatever data that is not supposed to be sorted. sometime seems that stop working but is not, (keep finding data to sort)
Please i need to Add the right snipped, can someone help me?
This is the Code
Code:
Sub Sort_M2L_Sheet1() ''To Change Start Column
'For i = 1 To LC Step 2 This 1 means column A and LC means last row.
'If you want to start column J, you can change from = 1 to = 10
Dim LC As Long, LR As Long, i As Long
Dim wsR As Worksheet
Set wsR = Sheets("Sheet1")
With wsR
LC = .Cells(3, Columns.Count).End(xlToLeft).Column
For i = 1 To LC Step 2
LR = .Cells(Rows.Count, i).End(xlUp).Row
With .Sort
.SortFields.Clear
.SortFields.Add Key:=wsR.Cells(2, i + 1), Order:=xlDescending
.SetRange wsR.Range(wsR.Cells(2, i), wsR.Cells(LR, i + 1))
.Header = xlYes
.Orientation = xlTopToBottom
.Apply
End With
Next
End With
End Sub
Thanks!