ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro loops and solver (VBA) (https://www.excelbanter.com/excel-programming/362301-macro-loops-solver-vba.html)

JCL

Macro loops and solver (VBA)
 

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



--
JCL
------------------------------------------------------------------------
JCL's Profile: http://www.excelforum.com/member.php...o&userid=34748
View this thread: http://www.excelforum.com/showthread...hreadid=545090


JCL[_2_]

Macro loops and solver (VBA)
 

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.


--
JCL
------------------------------------------------------------------------
JCL's Profile: http://www.excelforum.com/member.php...o&userid=34748
View this thread: http://www.excelforum.com/showthread...hreadid=545090



All times are GMT +1. The time now is 01:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com