Macro Issue with Do While Loop

jdpjtp910

Board Regular
Joined
Jul 20, 2010
Messages
67
I have this loop:

Code:
Dim blnTargetMet As Boolean
Dim UPBOrig As Currency
Dim UPBNew As Currency
Dim IR As Double
Dim IRCurrent As Double
Dim Term As Integer
Dim PITarget As Currency
Dim MPITarget As Currency
Dim PINew As Currency

blnTargetMet = False
UPBNew = UPBOrig
 
 
Do While blnTargetMet = False
    PINew = -Pmt((IR / 100) / 12, Term, UPBNew)
    If PINew < PITarget And PINew >= MPITarget Then
        blnTargetMet = True
        Exit Do
    End If
    UPBNew = UPBNew - 1
Loop

ANd everytime it runs, excel looks up. Any idea why?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
What is this vba code in?
Is it in an event?

and please describe more about excel 'looking up.'
Does it freeze?
 
Upvote 0
ANd everytime it runs, excel looks up. Any idea why?
Sounds like you might be caught in an endless loop (your condition never becomes True, so your looping never stops).

You might want to add some code to exit the loop after so many iterations, i.e.

Code:
Do While blnTargetMet = False
    If LoopCounter > 9999 Then
        MsgBox "You have exceeded 9999 loops"
        Exit Do
    End If
    PINew = -Pmt((IR / 100) / 12, Term, UPBNew)
    If PINew < PITarget And PINew >= MPITarget Then
        blnTargetMet = True
        Exit Do
    End If
    UPBNew = UPBNew - 1
    LoopCounter = LoopCounter +1
Loop
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,280
Members
452,902
Latest member
Knuddeluff

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