I have looked through a number of other related questions, but I haven't been able to really figure out how to create the macro I need. I am very new to VBA, basically ran into an issue that I can't solve without a macro and need to learn it now. Unfortunately I am on a deadline to try and get this done and will have to spend more time learning later.
I am using Solver to find an X value using two equations stored in columns AM and AN. I am using a dummy X and Y values in columns AO and AP, which are replaced with a correct value when I run the Solver Add-In.
The equations are:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">=IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$3, ([@[Current Stock - MUUS]]/[@Y])-$BI$3,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$4, ([@[Current Stock - MUUS]]/[@Y])-$BI$4,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$5, ([@[Current Stock - MUUS]]/[@Y])-$BI$5,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$6, ([@[Current Stock - MUUS]]/[@Y])-$BI$6,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$7, ([@[Current Stock - MUUS]]/[@Y])-$BI$7)))))</code>And:
<code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: pre-wrap; background-color: rgb(239, 240, 241);">=(([@[(X)]]/9.5)*12)-[@Y]</code>
I recorded the macro, and need to use a loop to run the Solver for the 8006 rows of the table. The table name is "Table13" in case that helps. The macro, as recorded is:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">' Run_Solver Macro
' Run solver for the array.
'
' Keyboard Shortcut: Ctrl+Shift+S
'
SolverOk SetCell:="$AN$3", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$3:$AP$3", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverDelete CellRef:="$AM$3", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$AM$3", Relation:=2, FormulaText:="0"
SolverOk SetCell:="$AN$3", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$3:$AP$3", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:="$AN$3", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$3:$AP$3", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
SolverOk SetCell:="$AN$4", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$4:$AP$4", Engine:=1, EngineDesc:="GRG Nonlinear"
End Sub</code>Any and all help would be very much appreciated!
MW
I am using Solver to find an X value using two equations stored in columns AM and AN. I am using a dummy X and Y values in columns AO and AP, which are replaced with a correct value when I run the Solver Add-In.
The equations are:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">=IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$3, ([@[Current Stock - MUUS]]/[@Y])-$BI$3,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$4, ([@[Current Stock - MUUS]]/[@Y])-$BI$4,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$5, ([@[Current Stock - MUUS]]/[@Y])-$BI$5,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$6, ([@[Current Stock - MUUS]]/[@Y])-$BI$6,
IF([@[Adjusted Factor % (Uses an Average Turn per Month to Calculate)]]=$BH$7, ([@[Current Stock - MUUS]]/[@Y])-$BI$7)))))</code>And:
<code style="margin: 0px; padding: 1px 5px; border: 0px; font-size: 13px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: pre-wrap; background-color: rgb(239, 240, 241);">=(([@[(X)]]/9.5)*12)-[@Y]</code>
I recorded the macro, and need to use a loop to run the Solver for the 8006 rows of the table. The table name is "Table13" in case that helps. The macro, as recorded is:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">' Run_Solver Macro
' Run solver for the array.
'
' Keyboard Shortcut: Ctrl+Shift+S
'
SolverOk SetCell:="$AN$3", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$3:$AP$3", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverDelete CellRef:="$AM$3", Relation:=2, FormulaText:="0"
SolverAdd CellRef:="$AM$3", Relation:=2, FormulaText:="0"
SolverOk SetCell:="$AN$3", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$3:$AP$3", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:="$AN$3", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$3:$AP$3", Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
SolverOk SetCell:="$AN$4", MaxMinVal:=3, ValueOf:=0, ByChange:= _
"$AO$4:$AP$4", Engine:=1, EngineDesc:="GRG Nonlinear"
End Sub</code>Any and all help would be very much appreciated!
MW