I've written a routine that deletes rows with either today or yesterdays date in column D or E. However the source data that i have comes in dd/mm/yyyy hh:mm:ss format, with such exact formats the routine doesn't work. this is even after i have changed the format which you can see earlier in the routine.
I've tested it on a seperate sheet manually inputting the dates and it works. How can i replace dd/mm/yyyy hh:mm:ss with something that will work with my routine?
Thanks
I've tested it on a seperate sheet manually inputting the dates and it works. How can i replace dd/mm/yyyy hh:mm:ss with something that will work with my routine?
Thanks
Code:
Sub Sheet3pm()
' deletes Rows 1:1
Rows("1:1").Select
Selection.Delete Shift = xlUp
' deletes Columns A:A
Columns("A:A").Select
Selection.Delete Shift:=xlLeft
Range("A:H").Select
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Key2:=Range("E2") _
, Order2:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, DataOption3:= _
xlSortNormal
' formats D:E to dd-mmm-yy
Columns("D:E").Select
Selection.NumberFormat = "d-mmm-yy"
Cells.Select
' Deletes Rows Containing Todays Date or Yesterdays
Last = Cells(Rows.Count, "D").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "D").Value) = (Date) - 1 Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "A").EntireRow.Delete
ElseIf (Cells(i, "D").Value) = Date Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "D").EntireRow.Delete
End If
Next i
Cells.Select
' Deletes Rows Containing Todays Date or Yesterdays
Last = Cells(Rows.Count, "D").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "E").Value) = (Date) - 1 Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "A").EntireRow.Delete
ElseIf (Cells(i, "E").Value) = Date Then
'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
Cells(i, "A").EntireRow.Delete
End If
Next i
End Sub