Hello Ralfie,
Add a Standard VBA Code Module to workbook. and then copy and paste the macro code below into it. For this macro to run correctly, it is assumed the data has been sorted as in your post, and the only columns used on the worksheet are A to D. This macro runs on the Active Worksheet.
Sub SortDatesAndTimes()
Dim Hours(24) As Integer
Dim LastRow As Long
Dim N As Integer
Dim NextDate, ThisDate
Dim Rng As Range
Dim Wks As Worksheet
Set Wks = ActiveSheet
LastRow = Wks.Cells(Rows.Count, "A").End(xlUp).Row
For I = 1 To LastRow - 1
ThisDate = Wks.Cells(I, "A").Value
N = Hour(Wks.Cells(I, "D").Value)
If Hours(N) = 0 Then
Hours(N) = N
Else
Wks.Range(Cells(I, "A"), Cells(I, "D")).ClearContents
End If
NextDate = Wks.Cells(I + 1, "A").Value
If ThisDate <> NextDate Then Erase Hours()
Next I
Set Rng = ActiveSheet.Range(Cells(1, "A"), Cells(LastRow, "D"))
Rng.SpecialCells(xlCellTypeBlanks).Delete (xlShiftUp)
End Sub
Sincerely,
Leith Ross
Bookmarks