Infinite Loop in worksheet change

earldunning

Active Member
Joined
Nov 9, 2006
Messages
263
Hello,
I have a worksheet that does some checking if certain cells are changed.
The worksheet is to gather information for software code to be implemented. One of the fields is "Release Number" which is the designated release they wish to implement the code.

If the date is too close to the actual implementation, the user can not move into or out of the release in the normal way. I have a "Lock down" date that I compare to today.

The code is perplexing me. I need to check that the release field (B15) is not being moved into a locked down release or out of. The "into" part is working fine and the "out of" is pretty similar code but puts it into an infinite loop.

The code in red is doing an infinite loop. The code in green is not. I have even tried replacing the NewLockDate in the good code withe CurrentLockDate but that throws it into a loop also.

Obviously it thinks it changing again and starts the code again. but why does it only loop for the first one and the others are fine? Any Ideas?
Code:
Dim NewLockDate As Date
Dim CurrentLockDate As Date
Dim DateToday As Date
Dim GoBack As Boolean


DateToday = Format(Now, "m/dd/yyyy")

If Target.Address(False, False) = "B15" And Range("B15").Value <> "" Then
    Range("Q2").Select
    Selection.Copy
    Range("Q3").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    CurrentLockDate = Range("Q3").Value
    CurrentLockDate = Format(CurrentLockDate, "m/dd/yyyy")
    If DateToday > CurrentLockDate Then
        'MsgBox ("New Lock date is " & NewLockDate)
        MsgBox ("Current Lock date is " & CurrentLockDate)
        MsgBox ("It is aleady past the scope lock date for this release. You can not add/modify/remove deliverables in the normal fashion. You must use a change form. To move the data to the Change Form use the button to the right.")
        [COLOR="Red"]Range("B15").Value = Range("Q1").Value[/COLOR]
        GoTo 10
    End If
    Range("Q4").Value = "=VLOOKUP(ReleaseNumberValue,ReleaseDatesList,7,0)"
    Range("Q4").Select
    Selection.Copy
    Range("Q4").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    NewLockDate = Range("Q4").Value
    NewLockDate = Format(NewLockDate, "m/dd/yyyy")
    Range("Q4").Value = ""
    MsgBox ("New Lock date is " & NewLockDate)
    MsgBox ("Current Lock date is " & CurrentLockDate)
    If DateToday > NewLockDate Then
        MsgBox ("It is aleady past the scope lock date for the release. You can not add/modify/remove deliverables in the normal fashion. You must use a change form. To move the data to the Change Form use the button to the right.")
       [COLOR="SeaGreen"] Range("B15").Value = Range("Q1").Value[/COLOR]
        GoTo 10
    Else
        [COLOR="seagreen"]Range("Q1").Value = Range("B15").Value[/COLOR]
    
        Range("B21").Value = "=VLOOKUP(ReleaseNumberValue,ReleaseDatesList,2,0)"
        Range("B22").Value = "=VLOOKUP(ReleaseNumberValue,ReleaseDatesList,3,0)"
        Range("B23").Value = "=VLOOKUP(ReleaseNumberValue,ReleaseDatesList,4,0)"
        Range("B24").Value = "=VLOOKUP(ReleaseNumberValue,ReleaseDatesList,5,0)"
        Range("B21:B24").Select
        Selection.Copy
        Range("B21").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
        Range("B16").Select
        Application.CutCopyMode = False
    End If
    'ActiveSheet.Unprotect Password:="security"
End If
10
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Before you change something:

Application.EnableEvents=False

and after

Application.EnableEvents=True
 
Upvote 0

Forum statistics

Threads
1,215,620
Messages
6,125,876
Members
449,268
Latest member
sGraham24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top