Add a User-selected range to Solver Macro

samanthalane

New Member
Joined
Jul 10, 2009
Messages
1
Ok I admit I may be a little over my head trying this but I want to score some brownie points in my internship.

I used the macro recorder to record a macro for using solver as shown below:

Sub BreakEven()
'
' BreakEven Macro
'


SolverOk SetCell:="$G$32", MaxMinVal:=3, ValueOf:="250000", ByChange:= _
"$D$2:$D$31"
SolverSolve
End Sub

Everything will stay the same except that the ValueOf:="250000" I want to be user selected by choosing the cell on another worksheet.

Another thought I had is that the cell containing the "250000" will always be the same cell referenced so I'm guessing I can somehow easily define a variable to plug into the code above so that it would be something like: ValueOf:="cost" and then somewhere I define cost referencing that "250000" cell (which is on another page)

Help please. I'm sure these are silly basic questions.
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
Hello Samantha and welcome to MrExcel.

Try something like this

Rich (BB code):
Sub BreakEven()
'
' BreakEven Macro
'


SolverOk SetCell:="$G$32", MaxMinVal:=3, ValueOf:=Sheets("Sheet1").Range("G4").Value, ByChange:= _
"$D$2:$D$31"
SolverSolve
End Sub
Change the sheet name and cell to suit.
 

Forum statistics

Threads
1,081,441
Messages
5,358,694
Members
400,508
Latest member
fish31

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top