How do I create a VBA macro in Excel that uses the goal seek function?

gkisystems

Board Regular
Joined
Apr 20, 2012
Messages
76
How do I create a VBA macro in Excel that uses the goal seek function?


Set Cell: C49
To Value: (whatever I have in cell L47)
By changing cell: B19


As I change the value in cell L47. I want the macro to automatically run in the background.
 
After further searching, found help via Stack Overflow, modified for my specific purpose. FYI, code I used ...
Code:
Sub GoalSeek_To_0()
' Macro created 15 Jun '18 by Benjamin Cohen


On Error Resume Next


Dim row_, col_ As Range
Dim i_, j_ As Integer
' i_ = 1
  j_ = 1


For Each col_ In Selection.Columns
 For Each row_ In Selection.Rows
  row_.Cells(1, j_).GoalSeek Goal:=0, ChangingCell:=row_.Cells(1, j_).Offset(0, -1)
   row_.Cells(1, j_).Value = 1
 Next row_
  j_ = j_ + 1
Next col_


End Sub
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hello everybody

I am new to using macros with Excel, and I believe what I try to achieve is discussed in this thread.

In a nutshell, I have two worksheets A and B.
Sheet A has a lot of user inputs.
Worksheet B is in the background performing calcuations based on the info in sheet A.
I would like to habe a button in sheet A that is linked to a macro, which performs the goals seek function within sheet B.
I would like the goal seek function to take all its input automatically from cells in sheet B.

My apologies for being a newbie. Any help you could give me (either existing resources or direct help) would be much appreciated.

Thank you all very much in advance.
 
Upvote 0

Forum statistics

Threads
1,213,530
Messages
6,114,162
Members
448,554
Latest member
Gleisner2

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