solver code

nikkki

New Member
Joined
Jan 4, 2007
Messages
34
Hello everyone,
I have a problem with solver code, this is my code:

Code:
Private Sub CommandButton1_Click()
Worksheets("teliko").Activate
solverReset
    SolverOk SetCell:="$g$318", MaxMinVal:=3, ValueOf:="$g$322", ByChange:="$c$26:$c$35"
Dim i As Integer, s As String, m As Integer

m = 393

For i = 322 To m Step 1
s = VBA.Format(i, "0")
SolverAdd CellRef:="$f$ & s", _
    Relation:=1, _
    FormulaText:="$g$ & s- 1"
Next i
    SolverSolve
    ActiveWorkbook.RefreshAll
    End Sub

This code does not work all the time. Sometimes it does not recognise the
ValueOf:="$g$322". When I replace it with the number (for example 35) it does work. The problem is that the value of g322 is not the same for all the problems. It is a reference cell. Any help please?
Niki
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,896
Messages
5,766,992
Members
425,392
Latest member
Booknerd

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