This macro uses a helper column (K in your example data). It uses a formula to return the priority based on the contents of F and J
Priority descending:
1: F= empty, J = time
2: F and J = time
3: F = Time, J = empty
4: F and J are empty
Then it sorts based on the priority column and columns F and J. It then deletes the priority helper column after the sort.
Sub Sort_Times()
Dim Lr As Long, Lc As Long
Lr = Cells.Find("*", , , , 1, 2).Row
Lc = Cells.Find("*", , , , 2, 2).Column + 1
Application.ScreenUpdating = False
Cells(1, Lc).Resize(Lr).FormulaR1C1 = "=IF((RC[-5]=0)*(RC[-1]>0),1,IF((RC[-5]>0)*(RC[-1]>0),2,IF((RC[-5]>0)*(RC[-1]=0),3,4)))"
Range("A1", Cells(Lr, Lc)).Sort Key1:=Cells(1, Lc), Order1:=xlAscending, _
Key2:=Range("F1"), Order2:=xlAscending, _
Key3:=Range("J1"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
Columns(Lc).Clear
Application.ScreenUpdating = True
End Sub
Bookmarks