In cells A1 and A2, I have a concatenate formula that produces X1:X2 and Y1:Y2 respectively, where in both the letter and numerical values are dependent on certain formulas in the worksheet.
In VBA, I wish to sort out the describe ranges in A1 and A2 separately. I tried the following formula, but it didn't work:
Sub Sort()
Dim myrange1 As String
Dim myrange2 As String
myrange1 = A1
myrange2 = a2
Range(myrange1).Select
ActiveWorkbook.Worksheets("Sample generator").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sample generator").Sort.SortFields.Add Key:=Range( _
"X2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sample generator").Sort
.SetRange Range(myrange1)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range(myrange2).Select
ActiveWorkbook.Worksheets("Sample generator").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sample generator").Sort.SortFields.Add Key:=Range( _
"X4"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Sample generator").Sort
.SetRange Range(myrange2)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Thanks!