I recorded the macro and get this code:
ActiveWorkbook.Worksheets("PM Close").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("PM Close").Sort.SortFields.Add Key:=Range( _
"H2:H991"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("PM Close").Sort.SortFields.Add Key:=Range( _
"G2:G991"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("PM Close").Sort
.SetRange Range("A1:P991")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
If I change it to
ActiveWorkbook.Worksheets("PM Close").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("PM Close").Sort.SortFields.Add Key:=Range( _
"H:H"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("PM Close").Sort.SortFields.Add Key:=Range( _
"G:G"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("PM Close").Sort
.SetRange Range("A1:P991")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
As you can see H2:H991 now is H:H and G2:G991 become G:H
Because I want to re-use this code for flexible row counts (the range I can replace by string later), but I wonder that the column range I change above, will or are they the same? I mean same sort result?
Bookmarks