Reputation: 109
I have the following range (obviously not mine, but MWE):
And I am looking to sort it using VBA. here is my code:
Sub test()
LR = ActiveWorkbook.Sheets(1).UsedRange.Rows.Count + ActiveSheet.UsedRange.Rows(1).Row - 1
Dim ws As Worksheet
Dim sort_range As Range
Set ws = ActiveWorksheet.Worksheets(1)
Set sort_range = ws.Range("C$2$:$E$" & LR)
Call sort_range.Sort(Key1:=sl_ws.Range("$C$2"), Order1:=xlAscending, _
Key2:=sl_ws.Range("$D$2"), Order2:=xlAscending, _
Key3:=sl_ws.Range("$E$2"), Order3:=xlAscending, _
Header:=xlYes)
End Sub
This returns that the following error:
directing me to this line:
Set sort_range = ws.Range("C$2$:$E$" & LR)
What am I doing wrong? Any help is appreciated.
Upvotes: 0
Views: 68
Reputation: 5750
Range("C$2$:$E$" & LR)
- you have the dollar signs in wrong places - should be Range("$C$2:$E$" & LR)
.
Upvotes: 4