在 vba 列中按日期对行进行排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13978458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sort row by date in a column vba
提问by David Van der Vieren
I Am trying to make my data sort each row by the date occuring in the N column. Right now it is only sorting the n column by istelf with out changeing around any other information. How do I re-Write my code so that the whole row will move as opposed to just the single cell in that row?
我试图让我的数据按 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
Got It with the following macro code
使用以下宏代码得到它
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
Sometimes I forget how easy it is to just record a macro!
有时我会忘记只录制一个宏是多么容易!
回答by David Van der Vieren
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