目前我的代码只排序包含所有" A"在范围内(E20:I20到最后一排)但我想要" A"如果任何行包含" A"在范围内(E20:I20到最后一行)。我坚持了下来。欢迎任何帮助。
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