Custom order sort

前端 未结 2 1796
温柔的废话
温柔的废话 2021-01-16 09:38

Hi I would like to sort the whole C column based on the values(Critical, high, medium,low). I am running this code on macro enabled worksheet

Here is my code.

<
2条回答
  •  执笔经年
    2021-01-16 10:12

    Try:

    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range("A:A") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
        "Critical,High,Medium,Low", DataOption:=xlSortNormal
    
        With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A:A")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    

提交回复
热议问题