I need some help with some VBA Excel code to format a spreadsheet please.
I have to run a report that give me an excel spreadsheet which has an invoice date in column P. I need to delete the entire row if the invoice date in the cell in column P is less than or equal to 60 days from todays date, and also delete any row that has an invoice date in column P of 4 years or more from todays date.
I normally have to do this manually each time I run the report so I would like to automate the process with some VBA code. Can anyone help me with this please.
Dim x As Long
For x = [a1].SpecialCells(xlCellTypeLastCell).row To 1 Step -1
Debug.Print Cells(x, "P").Value
If CDate(Cells(x, "P")) > Date - 60 Then
Cells(x, "P").EntireRow.Delete
Else
Exit Sub
End If
Next x
I got the above code to work