Sorting by Text Value in VBA
在电子表格上运行VBA功能后,我想自动对数据进行重新排序,因此用户不必这样做。 我尝试完成的排序选项如下:
我的vba代码当前为:
1 | 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列将正确排序,尽管其他2列将不会基于
我想做的事可能吗? 有谁知道指定这些排序顺序的方法?
使用宏记录器使我看到以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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 |
希望那应该做你想要的。