+ Reply to Thread
Results 1 to 3 of 3

Error when trying to run a recorded macro for Solver

  1. #1
    Registered User
    Join Date
    11-23-2022
    Location
    London
    MS-Off Ver
    365
    Posts
    8

    Question Error when trying to run a recorded macro for Solver

    Hello,

    I have two Solver scenarios (logics) that run as it should when run manually. The two scenarios are similar but different at the same time. They calculate the following:

    - Scenario 1: Cheapest combination based on user packs
    - Scenario 2: Cheapest combination on a per user basis

    Based on what the user inputs in cell E3, running solver will output a price (F3 and F13) for each scenario. We will then take the cheapest price from the two scenarios.

    I've tried to automate the process of manually running both Solver scenarios, by recording my steps in a Macro (Ctrl + Shift + A). However, running the Macro immediately gives me a compile error (Sub or Function not defined) and I don't know why.

    It would be great if you guys could help me understand the following:

    - Why the Macro I've recorded errors immediately? i.e. is there an option I've not ticked in order for the Macro to work with Solver?
    - If the Macro worked, I also have a problem. Because the Macro automates the process of using Solver from Scenario 1 and then 2. That means Solver will have Scenario 2 loaded after running the Macro and so running the Macro again will not solve Scenario 1. What will be the best way to fix this problem?

    The ideal is the satisfy the above but understand I'm not that close yet.

    Thanks in advance
    Attached Files Attached Files
    Last edited by arf26; 11-30-2022 at 06:07 PM.

  2. #2
    Registered User
    Join Date
    11-23-2022
    Location
    London
    MS-Off Ver
    365
    Posts
    8

    Re: Error when trying to run a recorded macro for Solver

    So I've had success in fixing the Compile Error. It was because I needed to tick Solver in the VBA References.

    However, still no breakthrough with my 2nd point. If Solver is loaded with Scenario 1, it will work as it should but then it errors with a Load Model: Invalid Constraint Formula. Initial findings suggests the Macro does not load the 2nd scenario, thus throwing an error.

    Is there a better way of to work out the cheapest price when comparing both scenarios? Any advice?
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-23-2022
    Location
    London
    MS-Off Ver
    365
    Posts
    8

    Re: Error when trying to run a recorded macro for Solver

    I've solved it! Thanks for viewing my post!

+ 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] Recorded Macro always gives error
    By Chilean087 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-29-2021, 10:27 AM
  2. Compile error on newly recorded macro
    By spachick in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-09-2020, 10:26 AM
  3. Recorded Macro that has error
    By exc1967 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-02-2020, 01:53 PM
  4. Run Recorded Macro but has error
    By Faye_Xu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-28-2015, 02:29 AM
  5. Recorded macro is having copy and paste error
    By Butcher1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-09-2014, 12:21 PM
  6. Recorded macro gets formula error
    By CityMPLSEmpolyee in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-10-2012, 09:28 AM
  7. Error in a simple recorded Macro
    By modytrane in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-10-2008, 11:23 AM

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