VBA for solver using active cell column but fixed row

GGG411

New Member
Joined
Feb 24, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have recorded a solver macro as per below.
I'd like to know how to make the column reference throughout the macro (in the below case "BH") change to be the column of the active cell.

SolverOk SetCell:="BH172", MaxMinVal:=1, ValueOf:=0, ByChange:="BH$51", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:="$BH$51", Relation:=1, FormulaText:="1"
SolverOk SetCell:="$BH$172", MaxMinVal:=1, ValueOf:=0, ByChange:="$BH$51", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverDelete CellRef:="$BI$62", Relation:=1, FormulaText:="$BI$89"
SolverAdd CellRef:="$BH$62", Relation:=1, FormulaText:="$BH$89"
SolverOk SetCell:="$BH$172", MaxMinVal:=1, ValueOf:=0, ByChange:="$BH$51", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverDelete CellRef:="$BI$62", Relation:=3, FormulaText:="$BI$88/0.97"
SolverAdd CellRef:="$BH$62", Relation:=3, FormulaText:="$BH$88/0.97"
SolverOk SetCell:="$BH$172", MaxMinVal:=1, ValueOf:=0, ByChange:="$BH$51", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverOk SetCell:="$BH$172", MaxMinVal:=1, ValueOf:=0, ByChange:="$BH$51", _
Engine:=1, EngineDesc:="GRG Nonlinear"
SolverSolve
Range("BI97").Select
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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