VBA Questions - New to Macros

KevinZ

New Member
Joined
Apr 14, 2019
Messages
33
Sorry for the long post, any help is appreciated.

I am working on the Macro below. I am hoping someone can provide a little guidance on a few questions.

1. Should the Marco be in Module1, The spreadsheet I am running it against or in ThisWorkbook?
2. I can run the solver without an issue, When I try to run the exact same thing in the Macro, I get a Compile error on the SolverReset function. Is there something I need to change?
3. When I create my loop, do I need to loop to the start of the constraints or is there a better way to do this?
4. Is there a good resource for me to learn about putting the results on the new spreadsheet in separate rows for each loop?
5. I want to set a maximum number of times for each value to be used in the results. Is there a good resource for me to learn how to do this?

Option Explicit
Sub TestSolve()
'
'Should this be in Module1, The spreadheet I am running it against or ThisWorkbook?
' TestSolve Macro
'Steps
' 1. Reset Solver
' 2. Create New Spreadsheet
' 3. Load Constraints
' 4. Add solution to spreadsheet
' 5. Loop - Does it need to start at Load Constraints? If not, where?

'Reset Solver - Getting Compile Error Sub or Function not defined
SolverReset

'Create New Spreadsheet - Named "Export"

'Set Constraints
'Note: Cell numbers to be changed to Column Names ($A$2:$A$134 changed to "Use") once columns are named

SolverOk SetCell:="$L$4", MaxMinVal:=1, ValueOf:=0, ByChange:="$A$2:$A$134", _
Engine:=1, EngineDesc:="GRG Nonlinear"
Solveradd CellRef:="$A$2:$A$134", Relation:=5, FormulaText:="binary"
Solveradd CellRef:="$L$10", Relation:=1, FormulaText:="$=L$5"
Solveradd CellRef:="$L$10", Relation:=3, FormulaText:="=$L$6"
Solveradd CellRef:="$L$9", Relation:=2, FormulaText:="=$L$8"
Solveradd CellRef:="$G$2:$G$134", Relation:=2, FormulaTest:="=$L$7"

'Need to set a maximum usage for each line.
' (Row 2($A$2) - 5 times, Row 3($A$3) - 6 times, row 4($A$4) - 2 times, etc)
' Can be a number or a percentage of times run (10%, 15%)
SolverSolve False

'Number of times to run - 1 to EndNumber
Dim StartNumber As Integer
Dim EndNumber As Integer

For StartNumber = 1 To EndNumber
EndNumber CellRef:="=$L$11"
Next StartNumber

End Sub

Thank you,
Kevin
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
2. I can run the solver without an issue, When I try to run the exact same thing in the Macro, I get a Compile error on the SolverReset function. Is there something I need to change?

Where do you have the code currently? in the sheet module?

Is Solver checked in Tools - References?
 
Last edited:
Upvote 0
Tools-References is not available on tihs currently.

What do you mean Tools - References is not available on this currently :confused:
 
Last edited:
Upvote 0
What do you mean Tools - References is not available on this currently :confused:

If you mean Tools - References is grayed out are you sure that you aren't still in Break mode?
 
Upvote 0
Maybe you didn't see my last post, are you still in break mode? If yes then click Run - Reset.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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