+ Reply to Thread
Results 1 to 6 of 6

Solver button working on one sheet but not another.

  1. #1
    Registered User
    Join Date
    05-09-2022
    Location
    Manitoba
    MS-Off Ver
    2022
    Posts
    3

    Solver button working on one sheet but not another.

    Hey all, hoping you can help.

    I am creating a workbook with multiple different sheets for solving for variables. I created a button on sheet 2 using the record function and it works great. I tried doing the same thing for sheet 1 but it gives "run-time error '1004'" Application-defined or object-defined error"

    I'm unsure what causes this. I will also point out that I can't even manually use solver on these sheet via the Data tab.

    Any help is appreciated.

    P.S. - Solver is enabled in my VBA and added to my worksheet, the file is .xlsm

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,791

    Re: Solver button working on one sheet but not another.

    Could it be that you are trying to run solver on a non active sheet? Because solver is build to run only on the active sheet.

    A limitation of the Solver is that all of the decision variables (adjustable or changing cells) in the By Changing Cells edit box must be cells on the active sheet. (This limitation makes the Solver considerably faster than if adjustable cells were allowed to be on any sheet.) You should re-design your Solver model so that all decision variables are on one sheet, and try again.
    Alf
    Last edited by Alf; 05-10-2022 at 12:46 AM.

  3. #3
    Registered User
    Join Date
    05-09-2022
    Location
    Manitoba
    MS-Off Ver
    2022
    Posts
    3

    Re: Solver button working on one sheet but not another.

    Quote Originally Posted by Alf View Post
    Could it be that you are trying to run solver on a non active sheet? Because solver is build to run only on the active sheet.



    Alf
    The function is supposed to solve using the sheet it is on. Could it be because the cells it calls are the same regardless of the sheet? It is in the VBA as $Q$16 or something for both functions since one sheet is similar to the other so I copied and built it up.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,791

    Re: Solver button working on one sheet but not another.

    I think you should upload the file as I'm not sure what function you are referring to
    The function is supposed to solve using the sheet it is on
    as I think of solver as an "Add-in" and not as a function.

    Alf

  5. #5
    Registered User
    Join Date
    05-09-2022
    Location
    Manitoba
    MS-Off Ver
    2022
    Posts
    3

    Re: Solver button working on one sheet but not another.

    Quote Originally Posted by Alf View Post
    I think you should upload the file as I'm not sure what function you are referring to

    as I think of solver as an "Add-in" and not as a function.

    Alf
    I've added it under manage attachments but I cannot seem to see it attached here.

    Here is the code however:

    Sub SolverSoldier()
    '
    ' SolverSoldier Macro
    '

    '
    SolverOk SetCell:="$Q$16", MaxMinVal:=3, ValueOf:=1, ByChange:="$L$16", Engine _
    :=1, EngineDesc:="GRG Nonlinear"
    SolverSolve userFinish:=True
    End Sub


    and then I created a function called SolverSheet which is the exact same but won't work on sheet 1.

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,791

    Re: Solver button working on one sheet but not another.

    Solver can only be run on the active sheet so you could make your function to a macro that sets sheet1 as the active sheet and the run solver. Alternative loop through Sheet1 and Sheet2

    Please Login or Register  to view this content.
    This macro will run solver on Sheet1 and Sheet2. It also assumes that the setting of target cell, cell to change and target value are the same on both sheets. Calling the solver engine it is sufficient to just name the engine i.e. Engine:=1 instead of Engine:=1, EngineDesc:=GRG Nonlinear. Excel is rather fuzzy when building macros. Adding the line "SolverReset" stops buildup of constraint when running solver in a loop. In this case really not needed.

    Alf

+ 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. [SOLVED] code not working when moving command button to different sheet
    By Chris1976 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-08-2020, 06:09 AM
  2. Copy and Paste from Sheet 11 to 12 via command button not working
    By OzDebP in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2019, 01:24 AM
  3. [SOLVED] Button visible on 'last sheet only' not working as expected
    By kjg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-15-2017, 05:11 PM
  4. [SOLVED] my add button not working as expected, i have included the workbook, see navigation sheet
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2016, 04:04 PM
  5. Macro Button not working for protected Sheet
    By sunny81 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-21-2015, 02:24 AM
  6. Protect sheet button is not working
    By Sophster in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-23-2011, 07:35 AM
  7. Command button not working properly on different sheet
    By Strikez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2007, 12:36 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