Here is some VBA code that someone named sosasola posted in another forum... it seems like the right code, but for some reason it doesn't work properly when I apply it to my spreadsheet.
The macro assumes that the 3 columns of data are placed in column A (Job Name), B (Product Type), C (Ship Date), the first task is to sort values in those columns the way that you suggested
first: according the column A
second: according the column C (descending)
third: according the column B
Next, it adds an extra temporary column and fills it up with temporary data, which is used for proper sorting operation. At the end of the code the temporary column is removed. It assumes that you have a header with Job Name, Product Type, and Ship Date, so the data starts from second row. Also, if data has more than 1000 rows, change all 1000's into data range or a bigger value.
Does this look/sound right to you? Any thoughts on why it didn't work properly?
Range("A2:C1000").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Key2:=Range("C2") _
, Order2:=xlDescending, Key3:=Range("B2"), Order3:=xlAscending, Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
'adding temporary column A:
Range("A1").Select
ActiveCell.EntireColumn.Insert
'filling up the temporary column:
Range("A2").Value = Range("D2").Value
For Each cell In Range("A3:A1000")
If Range("B" & cell.Row).Value <> Range("B" & cell.Row - 1) Then
Range("A" & cell.Row).Value = Range("D" & cell.Row).Value
Else
Range("A" & cell.Row).Value = Range("A" & cell.Row - 1).Value
End If
Next cell
'Now, sorting as you really desired:
Range("A2:D1000").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Key2:=Range("D2") _
, Order2:=xlDescending, Key3:=Range("C2"), Order3:=xlDescending, Header _
:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
' and removing unnecessary column A
Range("A1").Select
ActiveCell.EntireColumn.Delete
'done.
Please advise. Thanks!
Bookmarks