我试图让我的数据按 N 列中出现的日期对每一行进行排序。现在它只是按 istelf 对 n 列进行排序,而不改变任何其他信息。 如何重新编写我的代码,以便整行移动,而不是仅移动该行中的单个单元格?
Sub SortByDate()
Dim rSortRange As Range
Dim ws As Worksheet
Set ws = Sheets("Copy")
Set rSortRange = ws.Range("N11", "N111")
rSortRange.Sort Key1:=ws.Range("N11"), Order1:=xlAscending, _
Key2:=Range("N20"), Order2:=xlAscending, _
Key3:=Range("N29"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
End Sub
用下面的宏代码搞定了
Sub SortByDate()
Dim rSortRange As Range
Dim ws As Worksheet
Set ws = Sheets("Copy")
Set rSortRange = ws.Range("N11", "N111")
rSortRange.Sort Key1:=ws.Range("N11"), Order1:=xlAscending, _
Key2:=Range("N20"), Order2:=xlAscending, _
Key3:=Range("N29"), Order3:=xlAscending, _
Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
DataOption2:=xlSortNormal, DataOption3:=xlSortNormal
End Sub
有时我忘记了录制宏是多么容易!