[VBA] Use application.run to active sub error

linda410

New Member
Joined
Nov 9, 2017
Messages
1
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
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi, welcome to the board.
This line is causing a problem
Code:
If Sheet1.Monthlypayment.Value = True Then
What is "Monthlypayment" ?
I would also recommend changing the name of your Calculate sub. Using VBA Keywords for variables or macro names can cause problems & is best avoided.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top