Need to Give Goal Seek a Margin of Error in VBA

avd88

Board Regular
Joined
Jan 18, 2016
Messages
112
Hello,

Hoping someone can help me give goalseek a margin of error in VBA.

I created a spreadsheet that calculates how much you would pay on a loan if you are also getting a return (rent) on your investment.
My workbook has a couple of spreadsheets that use an amortization table, currency conversions (investment in another country), etc.

I added a vba button with goalseek that would tell me what is the maximum downpayment I can put in after all other variables are set (years, interest rate, rent, etc.) so that my loan payments are equal to my rent.
Because there are so many calculations going on the function sometimes works but most of the times it goes haywire. Because I don't need a very precise level of accuracy I think I can fix the issue by giving the goalseek a margin of error of +-1 or even +-5.

Cell O1 is equal to Rent - Loan Payment.
Goal is O1 = 0.
By changing Cell E2 which is equal to Downpayment.

This is my code:

VBA Code:
Private Sub GoalSeek_Click()
Range("O1").GoalSeek _
    Goal:=0, _
    ChangingCell:=Range("E2")

End Sub

Thanks!!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello,

Hoping someone can help me give goalseek a margin of error in VBA.

I created a spreadsheet that calculates how much you would pay on a loan if you are also getting a return (rent) on your investment.
My workbook has a couple of spreadsheets that use an amortization table, currency conversions (investment in another country), etc.

I added a vba button with goalseek that would tell me what is the maximum downpayment I can put in after all other variables are set (years, interest rate, rent, etc.) so that my loan payments are equal to my rent.
Because there are so many calculations going on the function sometimes works but most of the times it goes haywire. Because I don't need a very precise level of accuracy I think I can fix the issue by giving the goalseek a margin of error of +-1 or even +-5.

Cell O1 is equal to Rent - Loan Payment.
Goal is O1 = 0.
By changing Cell E2 which is equal to Downpayment.

This is my code:

VBA Code:
Private Sub GoalSeek_Click()
Range("O1").GoalSeek _
    Goal:=0, _
    ChangingCell:=Range("E2")

End Sub

Thanks!!
You could try making say P1 the margin of error (=5) then make Q1 = Rounddown(O1/P1,0) which will be 0 within the error margin and make the goal seek a value of 0 for Q1.
 
Upvote 0
Hy MrSyyr, that little hack worked! Thanks, I had tried something outside of VBA yesterday but couldn't get it to work well. Thanks again, great input!
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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