New Member
April 7, 2022
I have a requirement to sort an Excel file (2013) with 4 keys / 5 keys. The following vba code is not working and at the same time not throwing any error too. Need help /guidance. Please feel free to edit to get the results. Thanks in advance.
Sub ToSortFile()
Dim lastRow, LastCol As Long
lastRow = Cells(Rows.Count, 2).End(xlUp).Row
LastCol = Cells(2, Columns.Count).End(xlToLeft).Column
Set source_data = Range(Cells(2, 2), Cells(lastRow, LastCol))
Set Ws = Sheets("Details")
With Ws.Sort
.SortFields.Clear
.SortFields.Add Key:=Ws.Range("B2"), Order:=xlAscending
.SortFields.Add Key:=Ws.Range("C2"), Order:=xlAscending
.SortFields.Add Key:=Ws.Range("K2"), Order:=xlAscending
.SortFields.Add Key:=Ws.Range("M2"), Order:=xlAscending
.SetRange Ws.Range("B3:U" & lastRow)
.Header = xlYes
.Apply
End With
Trusted Members
Moderators
November 1, 2018
FYI, cross-posted here:
Answers Post
1 Guest(s)