I need to figure out how to change the below macro to delete all dates from 1 year ago prior to the month we are currently in. For example, because today is March 17th, the below will delete all rows prior to March 17th 2022, but I want all of March. I want it to delete everything prior to March vs. prior to March 17th.
Any suggestions?
Sub DeleteDateOlderThan365()
Dim lR As Long, R As Range, i As Long
lR = Range("G" & Rows.Count).End(xlUp).Row
Set R = Range("G1:G" & lR)
Application.ScreenUpdating = False
For i = lR To 1 Step -1
If IsDate(R.Cells(i)) Then
If Date - R.Cells(i).Value > 365 Then
R.Rows(i).EntireRow.Delete
End If
End If
Next i
Application.ScreenUpdating = True
End Sub
Any suggestions?
Sub DeleteDateOlderThan365()
Dim lR As Long, R As Range, i As Long
lR = Range("G" & Rows.Count).End(xlUp).Row
Set R = Range("G1:G" & lR)
Application.ScreenUpdating = False
For i = lR To 1 Step -1
If IsDate(R.Cells(i)) Then
If Date - R.Cells(i).Value > 365 Then
R.Rows(i).EntireRow.Delete
End If
End If
Next i
Application.ScreenUpdating = True
End Sub