Macro loops and solver (VBA)

J

JCL

Hello, Today I have taught myself a bit of VBA in order to create a
macro I need, but I am having trouble at the final hurdle. I am
assuming I have missed something very basic and someone will have
solved it in 5 minutes!

I need to use Solver, but have a whole column of data to use Solver on,
so am trying to create a loop function to apply the solver function to
each row in turn. I can get the macro to work for a single row, but
trying to get teh loop working is driving me insane! :confused:

Below is what I've put together. Set to just one row atm to get it
working (which it doesn't!). When I have the specific cell refs in it
works for the one row, but obviously not for more than that. So I have
tried to use relative referencing, and I think this might be where its
going wrong...

Any help very gratefully received!
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 24/05/2006 by JCL
'

'


For Counter = 101 To 101
Set curCell = Worksheets("Emission Factors").Cells(Counter,
14)

'SolverReset
SolverOk SetCell:=curCell, MaxMinVal:=2, ValueOf:="0",
ByChange:=curCell.Offset(0, 1)
SolverAdd CellRef:=curCell.Offset(0, 4), Relation:=2, FormulaText:=
_
"'[Reverse DMRB v2.xls]Input Page'!$C$13"
SolverOk SetCell:=curCell, MaxMinVal:=2, ValueOf:="0",
ByChange:=curCell.Offset(0, 1)
SolverOptions MaxTime:=100, Iterations:=100, Precision:=0.000001,
AssumeLinear _
:=False, StepThru:=False, Estimates:=1, Derivatives:=1,
SearchOption:=1, _
IntTolerance:=5, Scaling:=False, Convergence:=0.0001,
AssumeNonNeg:=True
SolverOk SetCell:=curCell, MaxMinVal:=2, ValueOf:="0",
ByChange:=curCell.Offset(0, 1)
SolverSolve UserFinish:=False
Next Counter



End Sub
 
J

JCL

Can anyone at least tell me how to refer to the cells in teh solver
function when a loop will do each row in turn? I obviously can't call
them D12 or whatever as the 12 will change with each run. I've tried
various things but none have worked.

Many thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top