VBAProIWish
Well-known Member
- Joined
- Jul 6, 2009
- Messages
- 1,027
- Office Version
- 365
- Platform
- Windows
Hello All,
Below I have code that was created when I used the macro recorder. The only problem is that I want to apply that code to sort a different range each time I run it.
How can the code below (in red and bold) be modified to sort by the range that contains the bottom-most row of data in column A?
Thanks
Below I have code that was created when I used the macro recorder. The only problem is that I want to apply that code to sort a different range each time I run it.
How can the code below (in red and bold) be modified to sort by the range that contains the bottom-most row of data in column A?
Code:
Sub aaa_test_macro_01()
Cells.Select
ActiveWorkbook.Worksheets("Totals").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Totals").Sort.SortFields.Add Key:= _
Range("[B][SIZE=4][COLOR=red]A2:A460[/COLOR][/SIZE][/B]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Totals").Sort.SortFields.Add Key:= _
Range("[SIZE=4][COLOR=red][B]B2:B460[/B][/COLOR][/SIZE]"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Totals").Sort
.SetRange Range("[SIZE=4][COLOR=red][B]A1:C460[/B][/COLOR][/SIZE]")
.header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
Thanks