Hi There - I'm trying to sort data by two levels in VBA. The table doesn't have a firm number of rows though.
Here is where I got (code not working):
Dim LevelOne As Range
Dim LevelTwo As Range
Dim SortRange As Range
LevelOne = ActiveSheet.Range(Range("A4"), Range("A4").End(xlDown)).Select
LevelTwo = ActiveSheet.Range(Range("F4"), Range("F4").End(xlDown)).Select
SortRange = ActiveSheet.Range(Range("4:4"), Range("4:4").End(xlDown)).Select
ActiveWorkbook.Worksheets("Fcst_{Enterprise}").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Fcst_{Enterprise}").Sort.SortFields.Add Key:=LevelOne, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Fcst_{Enterprise}").Sort.SortFields.Add Key:=LevelTwo, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange SortRange
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Any help with this is greatly appreciated
Here is where I got (code not working):
Dim LevelOne As Range
Dim LevelTwo As Range
Dim SortRange As Range
LevelOne = ActiveSheet.Range(Range("A4"), Range("A4").End(xlDown)).Select
LevelTwo = ActiveSheet.Range(Range("F4"), Range("F4").End(xlDown)).Select
SortRange = ActiveSheet.Range(Range("4:4"), Range("4:4").End(xlDown)).Select
ActiveWorkbook.Worksheets("Fcst_{Enterprise}").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Fcst_{Enterprise}").Sort.SortFields.Add Key:=LevelOne, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Fcst_{Enterprise}").Sort.SortFields.Add Key:=LevelTwo, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.ActiveSheet.Sort
.SetRange SortRange
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Any help with this is greatly appreciated