Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to write a piece of VBA CODE that will goal seek the variable value into the static value based on the input value

Excel1 !

ie. something along these lines but i manually did these,

Excel1 !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
204 views
Welcome To Ask or Share your Answers For Others

1 Answer

OK, here is what you have to do. First, you set the layout of your worksheet looks like this:

enter image description here

Here I use Sheet1. Please make changes accordingly if necessary.

In order to use Solver add-in, you must first make sure that the add-in is installed. For Office 2013 and later:

  1. Click the File tab, and then click Options below the Excel tab.
  2. In the Excel Options dialog box, click Add-Ins.
  3. In the Manage drop-down box, select Excel Add-ins, and then click Go.
  4. In the Add-Ins dialog box, select Solver Add-in, and then click OK.

After that, you must set a reference to the add-in in the workbook containing the code Visual Basic Editor (VBE) that calls the add-in's procedures. Click References on the Tools menu (see pictures below), and then select Solver under Available References.

enter image description here enter image description here

Now, go to worksheet 1 code module in VBE. Just click Sheet1 twice in VBE and paste the following code into it:

enter image description here

Sub VBASolver()
SolverReset
SolverOk SetCell:="$F$2", MaxMinVal:=3, ValueOf:=0, ByChange:="$B$2:$B$4"
SolverSolve True
End Sub

You can run the loaded VBA program by clicking Run icon below Debug menu or pressing F5 key on the keyboard.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...