Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,783
- Office Version
- 365
- Platform
- Windows
I have to sort many thousand rows by selection but each time I select the rows i want to sort the sort criteria keeps resetting itself. I done a recorded macro but obviously the range of rows change each time. What needs changing in code for the sort to work on my selected rows each time?
Thanks
Thanks
Code:
Sub Macro2()
'
' Macro2 Macro
'
'
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range( _
"C1037:C1040"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range( _
"AJ1037:AJ1040"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range( _
"AH1037:AH1040"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1037:AX1040")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Last edited: