多个键/订单上的 VBA Excel 变量排序

lin*_*mx1 3 sorting excel vba

如何同时对多个列(键/订单)进行排序?当我运行下面的代码时,它会在执行每一行时重新排序数据,而不是在排序中使用多列进行排序。将“密钥”或“订单”编号从 1 更改为 2 等无济于事。谢谢。

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
Run Code Online (Sandbox Code Playgroud)

Abe*_*old 6

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
Run Code Online (Sandbox Code Playgroud)