Deuce Bucksman
Board Regular
- Joined
- Jan 17, 2011
- Messages
- 102
Hello gurus.
Quick question: i'm trying to set up the inputs for the input boxes to send a message box and close the sub if the user enters anything that isn't a number (zero or text). I tried to use an onerror statement and set up a label below the sub, but i think i'm missing some key steps. If anyone can please give me some guidance on how to handle the error handling, I'd be very appreciative. Thanks so much for your help!
Private Sub CommandButton1_Click()
Dim principal As Variant
Dim interestrate As Variant
Dim payment As Variant
Dim startdate As Variant
Dim reply1 As Variant
Dim reply2 As Variant
Dim reply3 As Variant
reply1 = MsgBox("Hello, " & Application.UserName & "!" & " Would you like to change the amortization projection?", vbYesNo, "Amortization")
If reply1 = vbNo Then Exit Sub Else
GoTo amortization
amortization:
principal = Abs(InputBox("Please enter the total amount you'd like financed", "Principal Balance"))
On Error GoTo badentry
Exit Sub
interestrate = InputBox("Please enter the rate that you think you can get.", "Interest Rate")
payment = WorksheetFunction.Pmt(payment, interestrate, 360, 0)
reply2 = MsgBox("The monthly payment is " & Format(payment, "#,###") & "." & " Is this what you're looking for?", vbYesNo, "Payment")
If reply2 = vbYes Then
ActiveSheet.Range("A12") = payment
Else
MsgBox ("Might want to try again. Pretty sure I did everything correctly.")
Exit Sub
End If
badentry:
MsgBox ("bad entry")
End Sub
Quick question: i'm trying to set up the inputs for the input boxes to send a message box and close the sub if the user enters anything that isn't a number (zero or text). I tried to use an onerror statement and set up a label below the sub, but i think i'm missing some key steps. If anyone can please give me some guidance on how to handle the error handling, I'd be very appreciative. Thanks so much for your help!
Private Sub CommandButton1_Click()
Dim principal As Variant
Dim interestrate As Variant
Dim payment As Variant
Dim startdate As Variant
Dim reply1 As Variant
Dim reply2 As Variant
Dim reply3 As Variant
reply1 = MsgBox("Hello, " & Application.UserName & "!" & " Would you like to change the amortization projection?", vbYesNo, "Amortization")
If reply1 = vbNo Then Exit Sub Else
GoTo amortization
amortization:
principal = Abs(InputBox("Please enter the total amount you'd like financed", "Principal Balance"))
On Error GoTo badentry
Exit Sub
interestrate = InputBox("Please enter the rate that you think you can get.", "Interest Rate")
payment = WorksheetFunction.Pmt(payment, interestrate, 360, 0)
reply2 = MsgBox("The monthly payment is " & Format(payment, "#,###") & "." & " Is this what you're looking for?", vbYesNo, "Payment")
If reply2 = vbYes Then
ActiveSheet.Range("A12") = payment
Else
MsgBox ("Might want to try again. Pretty sure I did everything correctly.")
Exit Sub
End If
badentry:
MsgBox ("bad entry")
End Sub