Hi Guys,
I am having trouble writing a VBA code that would delete all rows if a cell contains a date of the prior month and prior year of the current month and current year . So far I have this, but I am currently stuck. Any tips would be appreciated. Thanks.
It concerns the cell B
Sub MyDeleteRows()
Dim lastrow As Long
Dim y As Long
Sheets("Sheet1").Select
With Sheets("Sheet1")
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = lastrow To 2 Step -1
If (Cells(i, 2).Value2 < Date) And _
((Month(Cells(i, 2)) < Month(Date)) Or _
(Year(Cells(i, 2)) < Year(Date))) _
Then Rows(i).EntireRow.Delete
Next i
End With
End Sub
I am having trouble writing a VBA code that would delete all rows if a cell contains a date of the prior month and prior year of the current month and current year . So far I have this, but I am currently stuck. Any tips would be appreciated. Thanks.
It concerns the cell B
Sub MyDeleteRows()
Dim lastrow As Long
Dim y As Long
Sheets("Sheet1").Select
With Sheets("Sheet1")
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
For i = lastrow To 2 Step -1
If (Cells(i, 2).Value2 < Date) And _
((Month(Cells(i, 2)) < Month(Date)) Or _
(Year(Cells(i, 2)) < Year(Date))) _
Then Rows(i).EntireRow.Delete
Next i
End With
End Sub