多个键/订单上的VBA Excel变量排序 [英] VBA Excel Variable Sorting on Multiple Keys/Orders
本文介绍了多个键/订单上的VBA Excel变量排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何同时对多个列(键/顺序)进行排序?当我运行下面的代码时,它将在执行每一行时对数据进行重新排序,而不是对具有多个列的排序进行排序.将键"或订单"号从1更改为2,等等,无济于事.谢谢.
How can I sort on multiple columns (keys/orders) at the same time? When I run my below code it re-sorts the data when executing each line instead of one sort with multiple columns in the sort. Changing the 'key' or 'order' number from 1 to 2, etc. does not help. Thanks.
wsLast_Row = Cells(Rows.Count, 2).End(xlUp).Row
Range("A3:BZ" & wsLast_Row).Sort key1:=Range("A3:A" & wsLast_Row), _
order1:=xlAscending, Header:=xlNo
Range("A3:BZ" & wsLast_Row).Sort key1:=Range("B3:B" & wsLast_Row), _
order1:=xlAscending, Header:=xlNo
Range("A3:BZ" & wsLast_Row).Sort key1:=Range("C3:C" & wsLast_Row), _
order1:=xlAscending, Header:=xlNo
Range("A3:BZ" & wsLast_Row).Sort key1:=Range("D3:D" & wsLast_Row), _
order1:=xlAscending, Header:=xlNo
Range("A3:BZ" & wsLast_Row).Sort key1:=Range("F3:F" & wsLast_Row), _
order1:=xlAscending, Header:=xlNo
推荐答案
Sub sdad()
wsLast_Row = Cells(Rows.Count, 2).End(xlUp).Row
With ActiveWorkbook.ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("A3:A" & wsLast_Row), Order:=xlAscending
.SortFields.Add Key:=Range("B3:B" & wsLast_Row), Order:=xlAscending
.SortFields.Add Key:=Range("C3:C" & wsLast_Row), Order:=xlAscending
.SortFields.Add Key:=Range("D3:D" & wsLast_Row), Order:=xlAscending
.SetRange Range("A3:BZ" & wsLast_Row)
.Header = xlNo
.Apply
End With
End Sub
这篇关于多个键/订单上的VBA Excel变量排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文