Hi,
I have a cell that contains a range which changes dynamically with a dataset. How do I get a code to reference that range rather than hardcoding, for example, "...Range($A$1:$A$2)...".
Better yet, here's the recorded macro:
Thanks!
I have a cell that contains a range which changes dynamically with a dataset. How do I get a code to reference that range rather than hardcoding, for example, "...Range($A$1:$A$2)...".
Better yet, here's the recorded macro:
Code:
Sub test()
'
' test Macro
'
'
ActiveWorkbook.Worksheets("REPORTS").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("REPORTS").Sort.SortFields.Add Key:=Range( _
"AF10:AF209"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("REPORTS").Sort.SortFields.Add Key:=Range( _
"AG10:AG209"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("REPORTS").Sort
.SetRange Range("AE9:AM209")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Thanks!
Last edited: