Forum Discussion

Francisco77's avatar
Francisco77
Copper Contributor
Aug 12, 2024

Macro Error

Hi All,

 

I generated a macro to first filter the values ​​of a column and remove the blanks, and then sort them from highest to lowest, but it generates the following error. What could it be due to?.

 

 

The Macro is:

 

 

 

1 Reply

  • Francisco77's avatar
    Francisco77
    Copper Contributor
    Sub Sort_High_to_Low()
    '
    ' Sort_High_to_Low Macro
    '
    ActiveSheet.Range("$B$5:$BV$400").AutoFilter Field:=9, Criteria1:="<>"
    '
    Range("B5:BO422").Select
    ActiveWorkbook.Worksheets("Final Rating").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Final Rating").Sort.SortFields.Add2 Key:=Range( _
    "J6:J422"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Final Rating").Sort.SortFields.Add2 Key:=Range( _
    "E6:E422"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Final Rating").Sort.SortFields.Add2 Key:=Range( _
    "C6:C422"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    ActiveWorkbook.Worksheets("Final Rating").Sort.SortFields.Add2 Key:=Range( _
    "B6:B422"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
    With ActiveWorkbook.Worksheets("Final Rating").Sort
    .SetRange Range("B5:BO422")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    End Sub

Resources