Use solver in VBA with loop in rows

joezzz

New Member
Joined
Apr 17, 2016
Messages
1
[TR]
[TD="class: votecell"][/TD]
[TD="class: postcell"]I am trying to use solver to find the root for 182 cells, each cell is depend only on one another variable, the output cell is from O2 to O183, the variable cell is from P2 to P183. I am trying to change the variable cells to have the output cell equal to 1. The code works but the results does not converge. Because I just want a fixed value of 1, I didn't set MaxMin value. The code is:


[/TD]
[/TR]

</tbody>


[TR]
[TD="class: votecell"]
do
[/TD]
[TD="class: postcell"][/TD]
[/TR]

<tbody style="px"margin:" 0px;="" padding:="" border:="" 0px;"=""></tbody>
Code:
<code style="margin: 0px; padding: 0px; border: 0px; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">[COLOR=#00008B]Sub[/COLOR][COLOR=#2E3133] Solver[/COLOR][COLOR=#2E3133]()[/COLOR][COLOR=#2E3133]
    [/COLOR][COLOR=#00008B]Dim[/COLOR][COLOR=#2E3133] setcellrange [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#2E3133] Range[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#2E3133] bychangerange [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#2E3133] Range
    [/COLOR][COLOR=#00008B]Dim[/COLOR][COLOR=#2E3133] i [/COLOR][COLOR=#00008B]As[/COLOR][COLOR=#00008B]Long[/COLOR][COLOR=#2E3133]
    [/COLOR][COLOR=#00008B]For[/COLOR][COLOR=#2E3133] i [/COLOR][COLOR=#2E3133]=[/COLOR][COLOR=#6b291b]2[/COLOR][COLOR=#00008B]To[/COLOR][COLOR=#6b291b]183[/COLOR][COLOR=#2E3133]
        [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#2E3133] setcellrange [/COLOR][COLOR=#2E3133]=[/COLOR][COLOR=#2E3133] Sheets[/COLOR][COLOR=#2E3133]([/COLOR][COLOR=#6B291B]"AshfordPierce"[/COLOR][COLOR=#2E3133]).[/COLOR][COLOR=#2E3133]Cells[/COLOR][COLOR=#2E3133]([/COLOR][COLOR=#2E3133]i[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#6B291B]15[/COLOR][COLOR=#2E3133])[/COLOR][COLOR=#2E3133]
        [/COLOR][COLOR=#00008B]Set[/COLOR][COLOR=#2E3133] bychangerange [/COLOR][COLOR=#2E3133]=[/COLOR][COLOR=#2E3133] Sheets[/COLOR][COLOR=#2E3133]([/COLOR][COLOR=#6B291B]"AshfordPierce"[/COLOR][COLOR=#2E3133]).[/COLOR][COLOR=#2E3133]Cells[/COLOR][COLOR=#2E3133]([/COLOR][COLOR=#2E3133]i[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#6B291B]16[/COLOR][COLOR=#2E3133])[/COLOR][COLOR=#2E3133]
        SolverReset
        SolverOk SetCell[/COLOR][COLOR=#2E3133]:=[/COLOR][COLOR=#2E3133]setcellrange[/COLOR][COLOR=#2E3133].[/COLOR][COLOR=#2E3133]Address[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#2E3133] ValueOf[/COLOR][COLOR=#2E3133]:=[/COLOR][COLOR=#6B291B]1[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#2E3133] ByChange[/COLOR][COLOR=#2E3133]:=[/COLOR][COLOR=#2E3133]bychangerange[/COLOR][COLOR=#2E3133].[/COLOR][COLOR=#2E3133]Address[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#2E3133] Engine[/COLOR][COLOR=#2E3133]:=[/COLOR][COLOR=#6B291B]1[/COLOR][COLOR=#2E3133],[/COLOR][COLOR=#2E3133] EngineDesc[/COLOR][COLOR=#2E3133]:=[/COLOR][COLOR=#6B291B]"GRG NONLINEAR"[/COLOR][COLOR=#2E3133]

        SolverSolve

[/COLOR][COLOR=#00008B]Next[/COLOR][COLOR=#2E3133] i
[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#00008B]Sub[/COLOR]</code>
When I use solver function out of VBA it works, but VBA results doesn't converge. Any help is appreciated. Nothing changed after running the Macro.
 

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