+ Reply to Thread
Results 1 to 2 of 2

VBA macro combining Solver and IF

  1. #1
    Registered User
    Join Date
    07-17-2017
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    2

    VBA macro combining Solver and IF

    Hello!

    I was trying to combine the use of the Solver function depending on the value saved in the cell with named "Corners_Bearing". I want the code to apply one solver if "Corners_Bearing"=2, another solver if "Corners_Bearing"=3 and nothing otherwise.

    I have tried the code without the if condition for every Solver and everything works. However when I put it all together it does not make any change although VBA is not giving me any error.

    Find the code below.

    Sub Corners_2_and_3bis()
    If Corners_Bearing = 3 Then
    SolverReset
    SolverAdd CellRef:="Solver_cellRefC3", Relation:=2, FormulaText:="0"
    SolverOk SetCell:="Solver_setCellC3", MaxMinVal:=1, ValueOf:="0", ByChange:="Solver_byChangeC3"
    SolverSolve True
    ElseIf Corners_Bearing = 2 Then
    SolverReset
    SolverAdd CellRef:="Solver_cellRefC2", Relation:=2, FormulaText:="0"
    SolverOk SetCell:="Solver_setCellC2", MaxMinVal:=1, ValueOf:="0", ByChange:="Solver_byChangeC2"
    SolverSolve True
    End If
    End Sub


    Any light on that?

    Thanks,

    Victor

  2. #2
    Registered User
    Join Date
    07-17-2017
    Location
    London, England
    MS-Off Ver
    2010
    Posts
    2

    Re: VBA macro combining Solver and IF

    Hello folks!

    I found it myself, I just missed the brackets [] in the variable for the if condition.

    The code looks like the following:

    Please Login or Register  to view this content.
    Moreover I wanted to trigger this Sub when changing the values of some cells grouped under the name of "Active_Macro". Therefore I added also this Private Sub in the sheet where the cells to be modified (Active_Macro range of cells) are located.

    Please Login or Register  to view this content.
    Let me know if you come across to a similar problem and you have trouble to make it run, I may be able to help you.

    Kind regards,

    Victor

+ 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. Replies: 1
    Last Post: 07-06-2016, 04:38 AM
  2. [SOLVED] combining For and Solver in VBA
    By Chris Greensmith in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2015, 03:57 AM
  3. Replies: 0
    Last Post: 07-20-2014, 12:45 PM
  4. macro not keeping solver solutions when solver is successful
    By jimmypants in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2014, 01:45 AM
  5. Can't start Solver. Error message says Solver.xlam already open.
    By DaveHills in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 1
    Last Post: 10-21-2012, 11:02 AM
  6. solver macro + simulation code + not updating solver values
    By sabinemaria in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2012, 11:37 AM
  7. lookup macro, solver macro, realtime macro
    By xelhelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2011, 06:14 PM

Tags for this Thread

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