Link to home
Start Free TrialLog in
Avatar of John Smith
John SmithFlag for Australia

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.Count, "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
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Smith

ASKER

Wow, you guys are quick. Yes the changes you make work THANKS.
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012