+ Reply to Thread
Results 1 to 6 of 6

Solver + Loop

  1. #1
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28

    Solver + Loop

    Hi

    I have a problem.
    Please see attached spreadsheet.

    What I want to do is not that complicated, but I am simply stucked.
    - if value in (col A) and (col C) are same
    - then (col F) = (col B)*(col E) + (col B)

    I want to run a solver in a loop so that
    - the macro finds each value of (col C) matching (col A)
    - if matching, the solver sets value in (col E) so that (col F) = 100
    - otherwise, leaves cell in col E blank

    so far, my code is like that and does not work

    Sub Button()

    Dim r As Range
    Dim c As Range
    Dim f As Range
    Dim p As Range

    Set r = Range("A2", Range("A65536").End(xlUp))
    Set f = Range("C2", Range("C65536").End(xlUp))

    For Each c In r.Cells
    For Each p In f.Cells
    If p = c Then
    SolverOk SetCell:=p.Offset(0, 3), MaxMinVal:=3, ValueOf:=100, bychange:=p.Offset(0, 2).Address
    SolverSolve True
    SolverFinish KeepFinal:=1

    End If
    Next p
    Next c

    End Sub
    I just feel stupid not beeing able to do this by myself
    I hope I am clear enough
    Thanks a lot in advance for your help.
    Attached Files Attached Files

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    In what way does it not work?
    Errors, unexpected results
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650
    Hi Have you done this Bit??
    --
    Before you use this function, you must establish a reference to the Solver add-in. With a Visual Basic module active, click References on the Tools menu, and then select the Solver.xla check box under Available References. If Solver.xla doesn't appear under Available References, click Browse and open Solver.xla in the \Office\Library\Solver\ subfolder.

    Regards Mick

  4. #4
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28
    Andy Pope >> the error is a classic vba one: Compile Error / Sub or Function not defined

    MickG >> My solver is correctly enabled in the addins list.

    Could someone help me?

    Thanks a lot in advance

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436
    MickG did not say the Addin's list.

    Re read his reply and then try again.

  6. #6
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28
    It works fine.

    Thanks a lot for your help

    HAve a nice day

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using Solver With Another Iterative Routine
    By kubota1000 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-03-2023, 12:37 AM
  2. Programming a Find Loop?
    By mcbain in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-21-2008, 04:44 AM
  3. Do Loop Until Loop
    By carsto in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-12-2007, 10:20 AM
  4. SOLVER add-on problems
    By fl4sh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2007, 12:10 PM
  5. Extend Loop From Within ?
    By Blewyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-26-2007, 05:34 AM

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