When I step through the code below, it runs the sort line but does not actually sort the data in excel. It was sorting fine yesterday, now it does not.
The data I am trying to sort is has the following form.
A B C D
1 Date Time Load On/OFF
2 mm/dd/yyyy #### #### On
3 mm/dd/yyyy #### #### Off
4 mm/dd/yyyy #### #### Off
Also this is my first post so I am not sure I am posting this code in the proper way.
The data I am trying to sort is has the following form.
A B C D
1 Date Time Load On/OFF
2 mm/dd/yyyy #### #### On
3 mm/dd/yyyy #### #### Off
4 mm/dd/yyyy #### #### Off
Also this is my first post so I am not sure I am posting this code in the proper way.
Code:
Sub SortDelete()
Dim LastRow As Long
Dim LastRowPeaks As Long
Dim x As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For x = 2 To LastRow Step 1
Cells(x, 5) = Month(Cells(x, 1)) & Year(Cells(x, 1))
Next x
Worksheets("Sheet3").Range("A1", Range("E1").End(xlDown)).sort _
Key1:=Range("D2", Cells(LastRow, "D")), _
Key2:=Range("E2", Cells(LastRow, "E")), _
Key3:=Range("C2", Cells(LastRow, "C")), _
order1:=xlAscending, order2:=xlAscending, order3:=xlDescending, _
header:=xlYes
For x = 2 To LastRow Step 1
If Cells(x, 5) <> Cells(x - 1, 5) Then
Cells(x, 6) = P
End If
Next x
Worksheets("Sheet3").Range("A1", Cells(LastRow, "F")).sort _
Key1:=Range("F2", Cells(LastRow, "F")), _
Key2:=Range("A2", Cells(LastRow, "F")), _
Key3:=Range("D2", Cells(LastRow, "F")), _
order1:=xlDescending, order2:=xlAscending, order3:=xlDescending, _
header:=xlYes
LastRowPeaks = Cells(Rows.Count, "F").End(xlUp).Row
Range(Cells(LastRowPeaks, "A"), Cells(LastRow, "A")).EntireRow.Delete
Range("F2", Cells(LastRowPeaks, "F")).EntireColumn.Delete
End Sub