Hi all,
The issue was I had a multilevel sort code that I wanted to sort by Job # then By Box # both in ascending order. However, for some reason I noticed in multiple areas that it was not properly sorted mostly because the data has a bunch of different style job #'s. Here is what was happening originally: (take a look at box 221 where the 1701 Cicero project was in the middle of 3XXX projects for no reason.
Here was my original code:
My new code which applies the correct sorting is the following. Can anyone help explain why I needed to add the 2nd range sort to get this to work properly? Or is there a better way to code this? Thanks in advance!
The issue was I had a multilevel sort code that I wanted to sort by Job # then By Box # both in ascending order. However, for some reason I noticed in multiple areas that it was not properly sorted mostly because the data has a bunch of different style job #'s. Here is what was happening originally: (take a look at box 221 where the 1701 Cicero project was in the middle of 3XXX projects for no reason.
Here was my original code:
VBA Code:
Sub MultiLevelSort()
Worksheets("User Inputs").Sort.SortFields.Clear
Range("A2:G" & Range("A" & Rows.Count).End(xlUp).Row).Sort Key1:=Range("D2"), Key2:=Range("B2"), Header:=xlYes, _
Order1:=xlAscending, Order2:=xlAscending, DataOption1:=xlSortTextAsNumbers
End Sub
My new code which applies the correct sorting is the following. Can anyone help explain why I needed to add the 2nd range sort to get this to work properly? Or is there a better way to code this? Thanks in advance!
VBA Code:
Sub MultiLevelSort()
Worksheets("User Inputs").Sort.SortFields.Clear
Range("A2:G" & Range("A" & Rows.Count).End(xlUp).Row).Sort Key1:=Range("D2"), Key2:=Range("B2"), Header:=xlYes, _
Order1:=xlAscending, Order2:=xlAscending, DataOption1:=xlSortTextAsNumbers
Range("A2:G" & Range("A" & Rows.Count).End(xlUp).Row).Sort Key1:=Range("B2"), Header:=xlYes, _
Order1:=xlAscending
End Sub