I'm not sure why the code below isn't working. I'm using this as a part of a larger VBA sub, but I'll just post the relevant code below
I want to sort a range (by A to Z) on a separate Workbook. The range is "A5:M600" and the worksheet is "Leaders". This is stored on the Workbook declared as 'wb2'.
The code below will get as far as opening the file where I want to execute the sort, select the range I want to sort, but it won't actually sort the selection.
Any ideas?
Sub SortWB2()
Dim wb2 As Workbook
Dim RetFilePath
'~~> Get the file path
RetFilePath = "T:\Purchasing\ADVENTURE RMS\Data Files\2015\Data.xlsx"
'if file path is not found, then exit the sub below
If RetFilePath = False Then Exit Sub
'set wb2 to open the file
Set wb2 = Workbooks.Open(RetFilePath)
With wb2.Worksheets("Leaders").Sort
.SetRange Range("A5:M600")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Application.DisplayAlerts = False
wb2.Close SaveChanges:=True
Application.DisplayAlerts = True
Set wb2 = Nothing
End Sub