# Solver macro for active row

#### jarvisjaska

##### New Member
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?

### Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

#### Jeffrey Mahoney

##### Well-known Member
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

#### jarvisjaska

##### New Member
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.

Replies
1
Views
613
Replies
1
Views
350
Replies
1
Views
295
Replies
0
Views
253
Replies
4
Views
236

Threads
1,127,540
Messages
5,625,411
Members
416,100
Latest member
lirongr1996

### 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

### 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