Hey All,
I'm trying to figure out why this won't work. Basically I want to store a range in a variable and and the use this variable in when using .sort.
I've tried a few things like storing rngr as a range, not using quotes. I'm at a bit of a dead end.
I'm trying to figure out why this won't work. Basically I want to store a range in a variable and and the use this variable in when using .sort.
I've tried a few things like storing rngr as a range, not using quotes. I'm at a bit of a dead end.
Code:
Sub New()
Dim rngr As String
rngr = Range("A2", Range("A2").End(xlDown).End(xlToRight))
ActiveWorkbook.Worksheets("XAQ").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("XAQ").Sort Key:=Range("rngr"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("XAQ").Sort
.SetRange Range("rngr")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub