I was replicating the loan amount calculator VBA.
Now I have created a button to get a calculated value. the calculation process is listed in the sub 'Calculate' which is in a module.
However, there is always an error message when i click the botton. i click debug and it yellow highlight the Application.Run "Calculate" in OptionButton2_Click().
Could anyone help me to make this code work, or show me how to debug and see which clause in the Sub Calculator is not functioning?
--------------------------------------
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then Range("C12").Value = "Yearly Payment": Application.Run "Calculate"
End Sub
---------------------------------------
Public Sub Calculate()
Dim loan As Long, rate As Double, nper As Integer
loan = Range("D4").Value
rate = Range("F6").Value
nper = Range("F8").Value
If Sheet1.Monthlypayment.Value = True Then
rate = rate / 12
nper = nper * 12
End If
Range("D12").Value = -1 * WorksheetFunction.Pmt(rate, nper, loan)
End Sub
Now I have created a button to get a calculated value. the calculation process is listed in the sub 'Calculate' which is in a module.
However, there is always an error message when i click the botton. i click debug and it yellow highlight the Application.Run "Calculate" in OptionButton2_Click().
Could anyone help me to make this code work, or show me how to debug and see which clause in the Sub Calculator is not functioning?
--------------------------------------
Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then Range("C12").Value = "Yearly Payment": Application.Run "Calculate"
End Sub
---------------------------------------
Public Sub Calculate()
Dim loan As Long, rate As Double, nper As Integer
loan = Range("D4").Value
rate = Range("F6").Value
nper = Range("F8").Value
If Sheet1.Monthlypayment.Value = True Then
rate = rate / 12
nper = nper * 12
End If
Range("D12").Value = -1 * WorksheetFunction.Pmt(rate, nper, loan)
End Sub