Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,748
- Office Version
- 365
- Platform
- Windows
I have recorded the macro below but I want to use it on different files with different amount of rows. What do I need to do for it to work on a used range rather than a set amount of rows like below please? Also the name of the sheet to be active sheet rather than a named sheet.
Code:
Sub Macro5()
ActiveWorkbook.Worksheets("Sheet").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet").Sort.SortFields.Add2 Key:=Range("A2:A2456" _
), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet").Sort
.SetRange Range("A1:T2456")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub