How do I write code to re-evaluate a range

September 19, 2018 at 13:28:09
Specs: Windows 7
I have a routine that runs one of 2 pieces of code depending on the value of a named range (LTV). The issue I am having is that at the time of the evaluation of the named range (LTV) is made it does not meet the criteria to trigger the PushTo95Button routine but after the code in the "else" is executed the criteria is now met to call the first routine (PushTo95Button). So I have to run the macro twice to get the desired result. Any suggestions on how I can evaluate the named range (LTV) after the first pass?
Sub PushTo105Button()
Range("D22").Value = 0
If Range("PropertyType").Value = "Condo" And Range("LTV").Value > 0.95 Then
   Call PushTo95Button
Else
   Range("LoanAmount").Value = Worksheets("Closing Costs").Range("I3")
End If
Call Calc_MI
End Sub


See More: How do I write code to re-evaluate a range

Reply ↓  Report •

#1
September 19, 2018 at 14:33:55
Either...

Sub PushTo105Button()
Range("D22").Value = 0
If Range("PropertyType").Value = "Condo" And Range("LTV").Value > 0.95 Then
   Call PushTo95Button
Else
   Range("LoanAmount").Value = Worksheets("Closing Costs").Range("I3")
     If Range("PropertyType").Value = "Condo" And Range("LTV").Value > 0.95 Then
       Call PushTo95Button
     End If
End If
Call Calc_MI
End Sub


or...

Sub PushTo105Button()
Range("D22").Value = 0
chkCondo:
    If Range("PropertyType").Value = "Condo" And Range("LTV").Value > 0.95 Then
      Call PushTo95Button
    Else
      Range("LoanAmount").Value = Worksheets("Closing Costs").Range("I3")
      GoTo chkCondo
    End If
   Call Calc_MI
End Sub

How To Post Data or Code ---> Click Here Before Posting Data or VBA Code


Reply ↓  Report •

#2
September 19, 2018 at 22:04:05
Thanks to a user from another forum I rethought the logic and rearranged the code to where the criteria is checked first and removed the condo check, I was already checking for condo on another routine so it was not necessary:
Sub PushTo105Button()
Range("D22").Value = 0
Range("LoanAmount").Value = Worksheets("Closing Costs").Range("I3")
Range("LoanAmount").Value = Worksheets("Closing Costs").Range("I3")
Call Calc_MI
End Sub


Reply ↓  Report •

#3
September 20, 2018 at 00:45:36
Why are you repeating the same instruction twice?

How To Post Data or Code ---> Click Here Before Posting Data or VBA Code


Reply ↓  Report •

Related Solutions

#4
September 20, 2018 at 04:22:11
Oops I removed that.

Reply ↓  Report •

Ask Question