Hey all,
First, thanks for taking the time to look at this thread. I have a written a loop that utilizes Excel Solver to calculated the best option for multiple columns. Here is my code so far:
Forgive the 'Else' line that seems to have a mind of its own...
Anyways, the first time, the code works great, but I receive the "Object Required" error on the line:
I feel like this should be an easy fix, but does anyone have any ideas what is causing this?
Thanks!
First, thanks for taking the time to look at this thread. I have a written a loop that utilizes Excel Solver to calculated the best option for multiple columns. Here is my code so far:
Code:
Sub Solver2()
Dim x As Integer
Dim A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q As Range
Sheets("Matrix").Activate
Set A = Range("C377")
Set B = Range("C21,C22,C23,C31,C32,C33,C42,C43,C44")
Set C = Range("C11")
Set D = Range("C35")
Set E = Range("C12")
Set F = Range("C46")
Set G = Range("C20")
Set H = Range("C21")
Set I = Range("C24")
Set J = Range("C10")
Set K = Range("C31")
Set L = Range("C32")
Set M = Range("C42")
Set P = Range("C43")
Set N = Range("C6")
Set O = Range("C5")
y = 1
For x = 1 To 365
If y = 8 Then
y = 0
Else:
SolverOk SetCell:=A, MaxMinVal:=2, ValueOf:=0, ByChange:= _
B, Engine:=1, EngineDesc:="GRG Nonlinear"
SolverAdd CellRef:=C, Relation:=2, FormulaText:=D
SolverAdd CellRef:=E, Relation:=2, FormulaText:=F
SolverAdd CellRef:=G, Relation:=2, FormulaText:= _
H & "*'[Doc.xlsm]Menu'!$D$12"
SolverAdd CellRef:=I, Relation:=2, FormulaText:=J
SolverAdd CellRef:=K, Relation:=2, FormulaText:= _
L & "*'[Doc.xlsm]Menu'!$D$12"
SolverAdd CellRef:=M, Relation:=2, FormulaText:= _
P & "*'[Doc.xlsm]Menu'!$D$12"
SolverAdd CellRef:=N, Relation:=1, FormulaText:=O
SolverSolve userFinish = True
End If
Set A = A.Offset(0, 1)
Set B = B.Offset(0, 1)
Set C = C.Offset(0, 1)
Set D = D.Offset(0, 1)
Set E = E.Offset(0, 1)
Set F = F.Offset(0, 1)
Set G = G.Offset(0, 1)
Set H = H.Offset(0, 1)
Set I = I.Offset(0, 1)
Set J = J.Offset(0, 1)
Set K = K.Offset(0, 1)
Set L = L.Offset(0, 1)
Set M = M.Offset(0, 1)
Set N = N.Offset(0, 1)
Set O = O.Offset(0, 1)
y = y + 1
Next
End Sub
Anyways, the first time, the code works great, but I receive the "Object Required" error on the line:
Code:
Set A = A.Offset(0,1)
Thanks!
Comment