mercredi 31 octobre 2018

If statement not executing properly in ByVal Target As Range

This code checks cell ranges based on the criteria provided in the Worksheet_Change(ByVal Target As Range). It works for the most part except for this one anomaly. When range SalesPrice changes it checks the loanamount value, "If my loan amount is under 271,050 and checkbox1.value is true" it goes to the next routine (this is correct behavior). But if I change the SalesPrice which re-calculates LoanAmount to a number that causes the LoanAmount to go over 271050 the MsgBox code does not execute. But if I retype the same SalesPrice again it does execute. So in order for it to work properly I have to type in the SalesPrice twice if chkbox1.value was initially checked for the code to detect that the LoanAmount is too high.

If Target.Address = "$D$5" Then 'Sales Price
If Range("LoanProgram").Value Like "*HFA Bond Miami*" And _
Range("SalesPrice").Value > 317646 Then MsgBox "Miami-Dade Bond Max Sales 
Price is $317,646"
If Range("LoanAmount").Value > 271050 And Sheets("Main").CheckBox1.Value = 
True Then
MsgBox "MDEAT Max Loan Amount is $271,050"
Sheets("Main").CheckBox1.Value = False
End If

Aucun commentaire:

Enregistrer un commentaire