+ Reply to Thread
Results 1 to 2 of 2

Macro loops and solver (VBA)

  1. #1
    Registered User
    Join Date
    05-24-2006
    Posts
    4

    HELP! 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!

    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
    Last edited by JCL; 05-24-2006 at 11:16 AM.

  2. #2
    Registered User
    Join Date
    05-24-2006
    Posts
    4
    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1