0

How do I alter the below code to effect deleting all rows occurring < 5pm Yesterday?

If wsR.Cells(r, "B") < CDate("18/06/2020 17:00:00") Then
    wsR.Rows(r).EntireRow.Delete
End If

My thinking is to substitute CDATE with something like (Date-1)+62400 to add 17 hours onto the beginning of yesterday but I have no idea how to structure the syntax. I have heard of calling in functions which is way above my skill level; and other threads negate addressing specific timestamps.

Any pointers would be appreciated.

jamheadart
  • 5,047
  • 4
  • 32
  • 63
  • 1
    https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/dateadd-function – braX Jul 08 '20 at 06:57
  • 1
    https://stackoverflow.com/questions/43454139/excel-vba-deleting-rows-in-a-for-loop-misses-rows – braX Jul 08 '20 at 06:59

1 Answers1

1
If wsR.Cells(r, "B") < DateAdd("h",17,Date-1) Then
    wsR.Rows(r).EntireRow.Delete
End If