RP1America
Technical User
Looking to delete rows if:
1) Cell A in row does NOT equal today's or yesterday's date.
2) Cell F in row equals cell G in same row.
When I run the code, everything gets deleted. Thoughts?
1) Cell A in row does NOT equal today's or yesterday's date.
2) Cell F in row equals cell G in same row.
When I run the code, everything gets deleted. Thoughts?
Code:
Sub DeleteRows()
Dim strDay, strDayLessOne, strMonth, strYear, strDate1, strDate2 As String
strDay = Format$(Day(Now), "00")
strDayLessOne = Format$(Day(DateAdd("d", -1, Now)), "00")
strMonth = Format$(Month(Now), "00")
strYear = Format$(Year(Now), "####")
strDate1 = "'" + strYear + "-" + strMonth + "-" + strDay + "*"
strDate2 = "'" + strYear + "-" + strMonth + "-" + strDayLessOne + "*"
Last = Cells(Rows.Count, "A").End(xlUp).Row
For i = Last To 1 Step -1
If (Cells(i, "F").Value) = (Cells(i, "G").Value) Then
Cells(i, "A").EntireRow.Delete
End If
If Not (Cells(i, "A").Value) Like strDate1 Then
If Not (Cells(i, "A").Value) Like strDate2 Then
Cells(i, "A").EntireRow.Delete
End If
Cells(i, "A").EntireRow.Delete
End If
Next i
End Sub