John Smith
asked on
Looping is not working using For - Next Code
I have a macro using For & Next. The code works if the code is run multiple times. I would like the code to complete the process by pressing the macro button once.
Can someone look at the code and make the necessary changes PLEASE.
This macro deletes all dates in column "B" if less than column "F" less another 5 days.
Sub DeleteRows_Dates()
Dim x As Long
Dim LastRow As Integer
Range("B3").Select
LastRow = ActiveSheet.Cells(Rows.Cou nt, "B").End(xlUp).Row
For x = 3 To LastRow
Debug.Print Cells(x, "B").Value
If CDate(Cells(x, "B")) < CDate(Cells(x, "F") - Day(5)) Then
Cells(x, "B").EntireRow.Delete
End If
Next x
End Sub
Deletes-Date2.xlsm
Can someone look at the code and make the necessary changes PLEASE.
This macro deletes all dates in column "B" if less than column "F" less another 5 days.
Sub DeleteRows_Dates()
Dim x As Long
Dim LastRow As Integer
Range("B3").Select
LastRow = ActiveSheet.Cells(Rows.Cou
For x = 3 To LastRow
Debug.Print Cells(x, "B").Value
If CDate(Cells(x, "B")) < CDate(Cells(x, "F") - Day(5)) Then
Cells(x, "B").EntireRow.Delete
End If
Next x
End Sub
Deletes-Date2.xlsm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome and I'm glad I was able to help.
Marty - MVP 2009 to 2012
Marty - MVP 2009 to 2012
ASKER