Attached is the "reduced" code (the problem still exists)
Sub Worksheet_Change(ByVal Target As Range)
Dim ProdCode As String
Dim PremLmt As Double
ProdCode = Replace(Range("product").Value, " ", "")
PremLmt = 1000000
'Exit Sub
Application.ScreenUpdating = False
Application.EnableEvents = False
' If Range("pSPnum") > 0 Then
shtInput.Range("pSP1a").Validation.ErrorMessage = "Total Premium contributions are limited to " & _
Format(PremLmt - (shtInput.Range("pSP2a") + shtInput.Range("pSP3a") + shtInput.Range("pSP4a") + shtInput.Range("pSP5a")), "$#,###,##0")
shtInput.Range("pSP2a").Validation.ErrorMessage = "Total Premium contributions are limited to " & _
Format(PremLmt - (shtInput.Range("pSP1a") + shtInput.Range("pSP3a") + shtInput.Range("pSP4a") + shtInput.Range("pSP5a")), "$#,###,##0")
shtInput.Range("pSP3a").Validation.ErrorMessage = "Total Premium contributions are limited to " & _
Format(PremLmt - (shtInput.Range("pSP1a") + shtInput.Range("pSP2a") + shtInput.Range("pSP4a") + shtInput.Range("pSP5a")), "$#,###,##0")
shtInput.Range("pSP4a").Validation.ErrorMessage = "Total Premium contributions are limited to " & _
Format(PremLmt - (shtInput.Range("pSP1a") + shtInput.Range("pSP2a") + shtInput.Range("pSP3a") + shtInput.Range("pSP5a")), "$#,###,##0")
shtInput.Range("pSP5a").Validation.ErrorMessage = "Total Premium contributions are limited to " & _
Format(PremLmt - (shtInput.Range("pSP1a") + shtInput.Range("pSP2a") + shtInput.Range("pSP3a") + shtInput.Range("pSP5a")), "$#,###,##0")
' End If
If Target.Address = Range("pSPnum").Address And Range("pSPnum") = 0 Then Range("pSPnum").Select
InputCheck.check_error
shtInput.Protect "Canada"
Application.EnableEvents = True
Application.ScreenUpdating = True
Sub check_error()
If shtAccEng.Range("MaxContribution") > 1000000 Then
MsgBox ("Flexible premium changed to keep contribution under $1,000,000")
shtInput.Range("pMPrem") = Application.RoundDown((1000000 - shtInput.Range("pSP1a") - shtInput.Range("pSP2a") - shtInput.Range("pSP3a") - shtInput.Range("pSP4a") - shtInput.Range("pSP5a")) / shtInput.Range("pMode"), 2)
End If
If shtAccEng.Range("MaxContribution") = 1000000 Then
MsgBox ("Contribution limit of one million met or exceeded - contribution stopped")
End If
End Sub
For date validation
only whole numbers are to be accepted
data between 0,=pLimit-C20-C24-C26-C28
pLimit = 1,000,000
Cell C20 = 100,000
I put in 950,000 - get the error message and rekey in 35,000 (I know that I originally used 950 and 35 - trying to keep things simple)
Nothing with input message
Error alert style - stop
Error alert title - Total premium contribution are limited to $900,000 (this is change by code above)
I believe that triggering the data validation (by exceeding the max) is causing two events to occur that I wasn't expecting - and therefore causing the looping.