TkdKidSnake
Active Member
- Joined
- Nov 27, 2012
- Messages
- 255
- Office Version
- 365
- Platform
- Windows
Hi all,
I am trying to add a sort function to a spreadsheet that varies in length, however the code stops when it gets to the .Apply section, does anyone know how to fix this?
See the code below:
Any help you can give on this would be greatly appreciated
Thanks in advance
I am trying to add a sort function to a spreadsheet that varies in length, however the code stops when it gets to the .Apply section, does anyone know how to fix this?
See the code below:
Code:
LastRow = sht.Range("A1").CurrentRegion.Rows.Countsht.Range("A2", sht.Range("k" & LastRow)).Select
'
ActiveWorkbook.Worksheets("RawData").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("RawData").Sort.SortFields.Add Key:=Range( _
"A2" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("RawData").Sort.SortFields.Add Key:=Range( _
"D2" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("RawData").Sort.SortFields.Add Key:=Range( _
"C2" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("RawData").Sort.SortFields.Add Key:=Range( _
"G2" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("RawData").Sort.SortFields.Add Key:=Range( _
"E2" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("RawData").Sort
.SetRange Range("A2" & LastRow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Any help you can give on this would be greatly appreciated
Thanks in advance
Last edited: