+ Reply to Thread
Results 1 to 11 of 11

VBA Solver with integer that changes

  1. #1
    Registered User
    Join Date
    04-20-2020
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    5

    VBA Solver with integer that changes

    Hello,

    I’m trying to use solver through VBA since my constrains will change. The problem im having is that my cell value is “0,1251” and after I run my code the solver used 1251 instead. How do I code my VBA so that the solver can read the decimal point?

    The value in for example cell(17,31) is 1,251 %

    Here is my code:

    Please Login or Register  to view this content.
    Last edited by Pepe Le Mokko; 04-20-2020 at 06:18 AM. Reason: Code tags

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: VBA Solver with integer that changes

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I did it for you this time. Please read forum rules. Thanks

  3. #3
    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,758

    Re: VBA Solver with integer that changes

    Solver does not always take kindly to the use of Scandinavian delimiter "," but sometimes one can fix it by using the US/UK delimiter "."

    Still the surest way to get help is to upload a file so forum members can test in order to find a solution.

    Alf

  4. #4
    Registered User
    Join Date
    04-20-2020
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    5

    Re: VBA Solver with integer that changes

    Hello Alf,

    Thank you for responding.

    I have tried to change the settings in Excel to use “.” Instead of “,”. It creates an error message:

    “Solver: an unexpected internal error occurred, or available memory was exhausted”


    I will attach the Excel file (although a bit messy). Hopefully, this makes it clearer.

    For every new std I want it to maximize my return.
    Attached Files Attached Files
    Last edited by Swestudent; 04-20-2020 at 03:47 PM.

  5. #5
    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,758

    Re: VBA Solver with integer that changes

    There is a problem with your model. The line
    Please Login or Register  to view this content.
    tells solver to ignore any solver message and keep on running to the end of the loop. Replacing this line with
    Please Login or Register  to view this content.
    will make the solver result box pop up with the message "Solver could not find a feasible solution". In the macro you specified that cell R33 should be equal to cell (17, y) i.e. AE17 a constraint that solver can't meet.

    Not sure but I think solver may have a problem with the MMULT formula in cell R32.

    You could try to contact the solver help desk
    https://www.solver.com/excel-solver-online-help
    and as a student you may be able to get the advanced solver for free.
    https://www.solver.com/welcome-students

    Alf

  6. #6
    Registered User
    Join Date
    04-20-2020
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    5

    Re: VBA Solver with integer that changes

    Thank you very much for trying to help me Alf!

    Although i know it cannot find the answer to the solution since 1251 is a number that is way to high. If I click on the solver after the macro it tells me that it tried 1251 instead of 0,1251 (my cell value in AE17). But I will try and find an answer with solver.

    Thank you again.
    Last edited by Swestudent; 04-21-2020 at 08:30 AM.

  7. #7
    Registered User
    Join Date
    04-20-2020
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    5

    Re: VBA Solver with integer that changes

    Hi again,

    If i change the code:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    It works, but for every iteration i need for AE17 to change on cell to the right (i.e next cell to be in the solver is AF17). Can i somehow code so that the second one "AE$17" changes one cell to the right in the next for-sling?

  8. #8
    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,758

    Re: VBA Solver with integer that changes

    So I had another go at it and this modification of you macro seems to solve the problem as far as I can see. I just added ".Address" to the CellRef:=$R$33 line and simplified your code a bit in the beginning.

    By the way you need to set the % format on cell AF17.

    Please Login or Register  to view this content.
    Alf
    Last edited by Alf; 04-21-2020 at 10:02 AM.

  9. #9
    Registered User
    Join Date
    04-20-2020
    Location
    Sweden
    MS-Off Ver
    Office 365
    Posts
    5

    Re: VBA Solver with integer that changes

    Alf, you are a lifesaver! Thank you so much!! It works and i have been pulling my hair over this "little" problem for days.

    THANK YOU!

  10. #10
    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,758

    Re: VBA Solver with integer that changes

    You are welcome

    Thanks for feedback and rep. Yes it's funny that a "small" could cause so much problems. I was so fascinated by this I spent most of today indoors (just what "folkhälsamyndigheten" recommends by the way) tinkering with it.

    If you are running your macro for a number of values you can speed shorten the run time by adding these two lines:

    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Alf

  11. #11
    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,758

    Re: VBA Solver with integer that changes

    You are welcome

    Thanks for feedback and rep. Yes it's funny that a "small" thing like this could cause so much problems. I was so fascinated by this I spent most of today indoors (just what "folkhälsamyndigheten" recommends by the way) tinkering with it.

    If you are running your macro for a number of values you can shorten the run time by adding these two lines:

    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    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] Binary Integer Programming Solver Help
    By OnlyAntony in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-13-2017, 02:13 PM
  2. Solver Integer Constraints and VBA
    By Larry Curcio in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-13-2010, 01:13 PM
  3. [SOLVED] Problem with Solver and Integer constraints
    By Tushar Mehta in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 04:05 PM
  4. Problem with Solver and Integer constraints
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  5. [SOLVED] Problem with Solver and Integer constraints
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  6. [SOLVED] Problem with Solver and Integer constraints
    By [email protected] in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  7. [SOLVED] Integer iterations in solver
    By Stevie D in forum Excel General
    Replies: 3
    Last Post: 07-24-2005, 09:05 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