[COLOR=darkblue]Sub[/COLOR] Calculate()
[COLOR=darkblue]Dim[/COLOR] y [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Double[/COLOR]
[COLOR=darkblue]Dim[/COLOR] n [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Double[/COLOR]
[COLOR=darkblue]Dim[/COLOR] r [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Double[/COLOR]
[COLOR=darkblue]Dim[/COLOR] z [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Double[/COLOR]
[COLOR=darkblue]Dim[/COLOR] s [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Double[/COLOR]
[COLOR=darkblue]Dim[/COLOR] success [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Boolean[/COLOR]
[COLOR=green]'turn off error handling while reading in values[/COLOR]
[COLOR=green]'the validation code below will control user input[/COLOR]
[COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]Resume[/COLOR] [COLOR=darkblue]Next[/COLOR]
[COLOR=green]'get and validate y[/COLOR]
success = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]Until[/COLOR] success = [COLOR=darkblue]True[/COLOR]
y = InputBox("Enter Loan Amount.", "Loan Amount")
[COLOR=darkblue]If[/COLOR] IsNumeric(y) And y > 0 [COLOR=darkblue]Then[/COLOR]
success = [COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]ElseIf[/COLOR] Err.Number <> 0 [COLOR=darkblue]Or[/COLOR] y < 1 [COLOR=darkblue]Then[/COLOR]
MsgBox "Please Enter a Valid Loan Amount Greater then zero 0"
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Loop[/COLOR]
[COLOR=green]'get and validate n[/COLOR]
success = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]Until[/COLOR] success = [COLOR=darkblue]True[/COLOR]
n = InputBox("Please Enter Years to Pay.", "Years to Pay")
[COLOR=darkblue]If[/COLOR] IsNumeric(n) And n > 0 [COLOR=darkblue]Then[/COLOR]
success = [COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]ElseIf[/COLOR] Err.Number <> 0 [COLOR=darkblue]Or[/COLOR] n < 1 [COLOR=darkblue]Then[/COLOR]
MsgBox "Please Eneter a Valid Number of Years to Pay" & vbCrLf _
& "Greater then Zero."
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Loop[/COLOR]
[COLOR=green]'get and validate r[/COLOR]
success = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]Until[/COLOR] success = [COLOR=darkblue]True[/COLOR]
r = InputBox("Please Enter Interest Rate.", "Interest Rate")
[COLOR=darkblue]If[/COLOR] IsNumeric(r) And r > 0 [COLOR=darkblue]Then[/COLOR]
success = [COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]ElseIf[/COLOR] Err.Number <> 0 [COLOR=darkblue]Or[/COLOR] r < 1 [COLOR=darkblue]Then[/COLOR]
MsgBox "Please Eneter a Valid Interest Rate" & vbCrLf _
& "Greater then Zero."
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]Loop[/COLOR]
[COLOR=green]'now the input values have been entered and validated[/COLOR]
[COLOR=green]'reset error handling back to default mode[/COLOR]
[COLOR=darkblue]On[/COLOR] [COLOR=darkblue]Error[/COLOR] [COLOR=darkblue]GoTo[/COLOR] 0
s = 1 * ((1 - ((r / 100) + 1) ^ n)) / (1 - (r / 100 + 1))
z = (y * ((r / 100) + 1) ^ n) / (12 * s)
MsgBox "The monthly repayment required to pay of the loan is £" & Round(z, 2)
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]