Excel VBA - multi level sorting -


how change code below sort in multi level way? @ present, code sorts table 1 column @ time, want sort multi level sort.

below im trying achieve:

enter image description here

here's code sorts table 1 column @ time:

range("a4:l" & lastrow).sort key1:=range("a4:a" & lastrow), _     order1:=xlascending, header:=xlno range("a4:l" & lastrow).sort key1:=range("b4:b" & lastrow), _     order1:=xlascending, header:=xlno range("a4:l" & lastrow).sort key1:=range("c4:c" & lastrow), _     order1:=xlascending, header:=xlno range("a4:l" & lastrow).sort key1:=range("d4:d" & lastrow), _     order1:=xlascending, header:=xlno range("a4:l" & lastrow).sort key1:=range("e4:e" & lastrow), _     order1:=xlascending, header:=xlno 

how change above sort together?

i recommend getting rid of recorded .sort method in favor of 'only need' vba sort code. however, there problem in can sort maximum of 3 sort keys per sort; solution perform 2 sort operations. sort highest ordinals first last 3 primary sort ordinals.

with worksheets("sheet1").range("a4:l" & lastrow)     .cells.sort key1:=.columns("d"), order1:=xlascending, _                 key2:=.columns("e"), order2:=xlascending, _                 orientation:=xltoptobottom, header:=xlyes     .cells.sort key1:=.columns("a"), order1:=xlascending, _                 key2:=.columns("b"), order2:=xlascending, _                 key3:=.columns("c"), order3:=xlascending, _                 orientation:=xltoptobottom, header:=xlyes end 

you've mashed cell addresses table columns or header labels in hte image not sure if got ordinals right. above sort column primary, b secondary, c third, d fourth , e fifth.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -