按VBA中的文本值sorting

在我的电子表格上运行VBA函数后,我想自动重新sorting数据,所以用户不需要。 我试图完成的sorting选项如下所示:

在这里输入图像说明

而我的vba代码目前是:

Columns("A:AA").Sort key1:=Range("C1:C1"), order1:=xlAscending, key2:=Range("G1:G1"), order2:=xlAscending, key3:=Range("A1:A1"), order3:=xlAscending, Header:=xlYes 

正如你所看到的,列A将正确sorting,但其他2将不会根据Fail, Dismissed, Passed标准和Critical, High, Medium, Low

我正在尝试做什么? 有谁知道一种方法来指定这些sorting?

使用macroslogging器带我到下面的代码:

 With ActiveSheet .Sort.SortFields.Clear .Sort.SortFields.Add Key:=.Range("C:C"), _ SortOn:=xlSortOnValues, _ Order:=xlAscending, _ CustomOrder:="Fail,Dismissed,Passed", _ DataOption:=xlSortNormal .Sort.SortFields.Add Key:=.Range("G:G"), _ SortOn:=xlSortOnValues, _ Order:=xlAscending, _ CustomOrder:="Critical,High,Medium,Low", _ DataOption:=xlSortNormal .Sort.SortFields.Add Key:=.Range("A:A"), _ SortOn:=xlSortOnValues, _ Order:=xlAscending, _ DataOption:=xlSortNormal .Sort.SetRange .Range("A:AA") .Sort.Header = xlYes .Sort.MatchCase = False .Sort.Orientation = xlTopToBottom .Sort.SortMethod = xlPinYin .Sort.Apply End With 

希望这应该做你想要的。