Solver macro for active row

jarvisjaska

New Member
Joined
Jan 13, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I've recorded a simple solver macro and I have two problems with it. The recorded code is shown below:

VBA Code:
Sub Macro1()
'
' Macro1 Macro
'

'
    SolverReset
    SolverOk SetCell:="$BU$8", MaxMinVal:=3, ValueOf:=0, ByChange:="$BC$8,$BQ$8", _
        Engine:=1, EngineDesc:="GRG Nonlinear"
    SolverOk SetCell:="$BU$8", MaxMinVal:=3, ValueOf:=0, ByChange:="$BC$8,$BQ$8", _
        Engine:=1, EngineDesc:="GRG Nonlinear"
    SolverSolve userFinish:=True
End Sub

Problem 1: Recorder didn't record constraints (cells BD8 and BO8 should both equal 0)
Problem 2: I want to be able to run the macro on the active row (ie. the row I'm currently on). For example, if I'm on row 11 I need to set cell BU11 to 0 by changing cells BC11 and BQ11. Also cells BD11 and BO11 should both equal 0.

Any ideas on how to solve these problems?
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
1,830
Office Version
  1. 365
Platform
  1. Windows
ActiveCell refers to the current selected cell
Activecell.offset(0,1) refers to the cell one column to the right of the current selected cell
Activecell.Row refers to the row of the selected cell
Range("BC" & Activecell.row).value = 0 changes BC11 to zero if the selected cell is on row 11
Range("BQ" & Activecell.row).value = 0 changes BQ11 to zero if the selected cell is on row 11
 
Solution

jarvisjaska

New Member
Joined
Jan 13, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
ActiveCell refers to the current selected cell
Activecell.offset(0,1) refers to the cell one column to the right of the current selected cell
Activecell.Row refers to the row of the selected cell
Range("BC" & Activecell.row).value = 0 changes BC11 to zero if the selected cell is on row 11
Range("BQ" & Activecell.row).value = 0 changes BQ11 to zero if the selected cell is on row 11
Thank you! Took a while to get it right, but now it's working perfectly.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,070
Messages
5,622,512
Members
415,904
Latest member
jchi2210

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
Top