Sub Macro4M()
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add(Range("A2:A20"), _
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, _
255, 0)
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A1:P20")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
我正在尝试对不存在数据的行和列进行排序,但在上面的代码中,排序操作仅适用于行 A2:A20 和列 A1:P20 我的条件是我想对工作表中的整行和整列应用排序 谁能帮我解决这个问题
Sub Macro4M()
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add(Range("A:A"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 255, 0)
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("A:P")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub