Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过VBA对行中的单词进行排序_Vba_Sorting_Excel - Fatal编程技术网

通过VBA对行中的单词进行排序

通过VBA对行中的单词进行排序,vba,sorting,excel,Vba,Sorting,Excel,目前,我的代码只对包含范围内所有“A”的行进行排序(E20:I20到最后一行),但如果任何行包含范围内的“A”(E20:I20到最后一行),我希望在顶部排序“A”。我受够了。欢迎任何帮助 Sub SortA() Range("A19").Select Range(Selection, Selection.End(xlToRight)).Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection

目前,我的代码只对包含范围内所有“A”的行进行排序(E20:I20到最后一行),但如果任何行包含范围内的“A”(E20:I20到最后一行),我希望在顶部排序“A”。我受够了。欢迎任何帮助

Sub SortA()

Range("A19").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Phop").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Phop").Sort.SortFields.Add Key:=Range("E20:E" & Range("E" & Rows.Count).End(xlUp).Row),  SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="A", DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Phop").Sort.SortFields.Add Key:=Range("F20:F" & Range("F" & Rows.Count).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="A", DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Phop").Sort.SortFields.Add Key:=Range("G20:G" & Range("G" & Rows.Count).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="A", DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Phop").Sort.SortFields.Add Key:=Range("H20:H" & Range("H" & Rows.Count).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="A", DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Phop").Sort.SortFields.Add Key:=Range("I20:I" & Range("I" & Rows.Count).End(xlUp).Row), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:="A", DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Phop").Sort
    .SetRange Range("A19:J" & Range("A" & Rows.Count).End(xlUp).Row)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With
Range("A20").Select


End Sub

如果您删除
CustomOrder
属性,会发生什么情况?CustomOrder属性是我准备好的列表,用于用“A”对其进行排序,您将正确地引用customlist:它是indexnumber。e、 g范围(“D1:D20”)。排序范围(“D1”),Ordercustom:=应用程序。customListcount@3689这看起来像是刚刚录制的。请看看这个