Hi all,
I'm getting the below error message when tyring to sort a range:
"Run-time error '1004': The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank."
I'm using the code below, and when I press the "debug" button it's hi-lighting the ".Apply" line in yellow:
I got the above code by recording a macro and it worked fine. There's proably a simple solution for this, but I have no idea what is causing the error.
Any ideas?
I'm getting the below error message when tyring to sort a range:
"Run-time error '1004': The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank."
I'm using the code below, and when I press the "debug" button it's hi-lighting the ".Apply" line in yellow:
Code:
Sub Sort_Trades()
Range("C5:M50").Select
ActiveWorkbook.Worksheets("Sort").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sort").Sort.SortFields.Add Key:=Range("C6:M50") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sort").Sort
.SetRange Range("C5:M50")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
End Sub
I got the above code by recording a macro and it worked fine. There's proably a simple solution for this, but I have no idea what is causing the error.
Any ideas?