jamescooper
Well-known Member
- Joined
- Sep 8, 2014
- Messages
- 834
Hello All, the following code allows me to sort the sheet by B2:B20544 and K2:K20544 with a range A1 to N20544.
How would I change this bit of the coding to make it dynamic - so that if when the number of rows changes?
Thanks a lot.
Cells.Select
ActiveWorkbook.Worksheets("Sheet0").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet0").Sort.SortFields.Add Key:=Range( _
"B2:B20544"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Sheet0").Sort.SortFields.Add Key:=Range( _
"K2:K20544"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sheet0").Sort
.SetRange Range("A1:N20544")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
How would I change this bit of the coding to make it dynamic - so that if when the number of rows changes?
Thanks a lot.
Cells.Select
ActiveWorkbook.Worksheets("Sheet0").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet0").Sort.SortFields.Add Key:=Range( _
"B2:B20544"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Sheet0").Sort.SortFields.Add Key:=Range( _
"K2:K20544"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sheet0").Sort
.SetRange Range("A1:N20544")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub