-
If you to want wait until the end before letting them know there is an error:
[vba]Private Sub Calculate_Monthly_Repayments_Click()
Dim y As Variant
Dim r As Variant
Dim n As Variant
Dim ratio As Double
Dim calc1 As Double
Dim calc2 As Double
Dim calc3 As Currency
startOver:
Do
y = Application.InputBox("Please enter the loan that is to be paid off", "Loan amount")
If TypeName(y) = "Boolean" Then
Exit Sub
ElseIf y <= 0 Then
Else
Exit Do
End If
Loop
Do
r = Application.InputBox("Now input the annual interest rate to be used")
If TypeName(r) = "Boolean" Then
Exit Sub
ElseIf r <= 0 Then
MsgBox "Please enter a positive value."
ElseIf Not IsNumeric(r) Then
MsgBox "Please enter a numeric value."
Else
Exit Do
End If
Loop
Do
n = Application.InputBox("Finally, enter the number of years in which the loan needs to be paid off")
If TypeName(n) = "Boolean" Then
Exit Sub
ElseIf n <= 0 Then
MsgBox "Please enter a positive value."
ElseIf Not IsNumeric(n) Then
MsgBox "Please enter a numeric value."
Else
Exit Do
End If
Loop
On Error GoTo handler
ratio = (r / 100) + 1
calc1 = y * (ratio ^ n)
calc2 = ((ratio ^ n) - 1) / (ratio - 1)
calc3 = calc1 / (calc2 * 12)
MsgBox ("The monthly payment required to pay off the loan is £") & Round(calc3, 2)
Exit Sub
handler:
If Err.Number = 6 Then
MsgBox "One of your enties is invalid, please try again", vbOKOnly + vbCritical
GoTo startOver
End If
End Sub[/vba]
Last edited by mbarron; 03-03-2010 at 10:37 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules