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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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