rickincanada
Board Regular
- Joined
- Aug 31, 2010
- Messages
- 61
Hi there! I'm trying to learn how to use VBA's Do-Until looping function to assist me in getting a payment rollback feature to work. I have a very simple workbook created that calculates a monthly payment based on the standard set of PMT Arguments. What I'm trying to do is get an input box that asks me what I want the monthly payment to be and then have it reduce or increase the Principal amount until it gets there.
Here's what I've written so far, however nothing happens after I enter my desired payment (NewPmnt) and click Yes.
Option Explicit
Sub PaymentRollback()
Dim NewPmnt As Variant
Dim OldPmnt As Double
'Range A4 is my Principal Amount
NewPmnt = InputBox("What do you want the payment to be?")
OldPmnt = Range("A6")
If Not IsNumeric(NewPmnt) Then
MsgBox ("You must enter a number!")
End If
If NewPmnt < 0 Then
MsgBox ("That's too low! Payment must be greater than 0.")
Do Until OldPmnt = NewPmnt
If NewPmnt > OldPmnt Then
Range("A4").Value = Range("A4").Value + 0.01
End If
Loop
Do Until OldPmnt = NewPmnt
If NewPmnt < OldPmnt Then
Range("A4").Value = Range("A4").Value - 0.01
End If
Loop
End If
End Sub
Thanks so much to anyone who can help. I'm really trying to learn this stuff on my own but this looping thing has me stuck!
Here's what I've written so far, however nothing happens after I enter my desired payment (NewPmnt) and click Yes.
Option Explicit
Sub PaymentRollback()
Dim NewPmnt As Variant
Dim OldPmnt As Double
'Range A4 is my Principal Amount
NewPmnt = InputBox("What do you want the payment to be?")
OldPmnt = Range("A6")
If Not IsNumeric(NewPmnt) Then
MsgBox ("You must enter a number!")
End If
If NewPmnt < 0 Then
MsgBox ("That's too low! Payment must be greater than 0.")
Do Until OldPmnt = NewPmnt
If NewPmnt > OldPmnt Then
Range("A4").Value = Range("A4").Value + 0.01
End If
Loop
Do Until OldPmnt = NewPmnt
If NewPmnt < OldPmnt Then
Range("A4").Value = Range("A4").Value - 0.01
End If
Loop
End If
End Sub
Thanks so much to anyone who can help. I'm really trying to learn this stuff on my own but this looping thing has me stuck!