Geoffrey Turner
Geoffrey Turner

Reputation: 89

Auto-deletion of Yesterday's Entries After a Set Time

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.

Upvotes: 0

Views: 30

Answers (1)

Geoffrey Turner
Geoffrey Turner

Reputation: 89

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

Upvotes: 1

Related Questions