+ Reply to Thread
Results 1 to 16 of 16

using variables in excel solver constraints problem!

  1. #1
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    using variables in excel solver constraints problem!

    Hi

    I've a big problem getting the Constraints in excel solver to use variables.
    It seems that the only accepted variable type in the contraints are STRING variables. THe following simple example works AS LONG AS the variable apa is a STRING value and as long as it doesn't contain decimals....

    So the question is. How to use varialbes in the FormulaText argement other than string values as integers?



    Please Login or Register  to view this content.

  2. #2
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    Anyone?

    How to use a varaible with decimals in the statement:

    FormulaText:= ???

    What is the syntax and what types are accepted?

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: using variables in excel solver constraints problem!

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    thanks!
    I've tried the cStr on my variable but it my real sheet the apa variable is actually a cell value (decimal number). Since I'm using the Swedish excel version our numbers use "," instead of "."

    IS there simple way of replacing the "," with a "." in VBA?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: using variables in excel solver constraints problem!

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    Ok thanks.
    But this won't replace the "," with a "." so that the Solver (VB uses the english way för decimals ".") will udnerstand the string value of a decimal number.

    TO clearify what have to be done is.

    Replace a number from a sheet (Swedish) such as 3,145 to a STRING (in order to get the solver to understand it) where the "," has been replaced with a "."

    Again, thanks Shg for all your support. I've learned som much from you.

  7. #7
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    Hmm, I've tried the
    Please Login or Register  to view this content.
    But when used as constraint in SOLVER it's read like

    314 INSTEAD of 3.14

    What's wrong here?!?!?!

    I've got Office 2000 professional

  8. #8
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    Hmm I've just tried
    Please Login or Register  to view this content.
    And it's read by excel's SOLVER as 314159!!!!!!!!
    I've also tried 3,141559 but it gives the same result....

    What is wrong here?? Can office 2000's solver only handle integer contraints labelled as STRING values????!?!?

    Please help!!

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: using variables in excel solver constraints problem!

    Try
    Please Login or Register  to view this content.
    Edit: Oops, I see you've tried that.

    Record a macro setting up Solver and see what it does.
    Last edited by shg; 02-09-2009 at 06:56 PM.

  10. #10
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    I get this when I record a Macro using the solver


    Please Login or Register  to view this content.
    And this code works but ONLY ONCE. When I copy this code into a controlbutton and run IT AGAIN 10,234 is READ like 10234 and "5,543" is read like "5543"

    I've tried
    Please Login or Register  to view this content.
    AND it GET THE SAME RESULT THAT IS 10234...

    imAYBY IT'S SOMETHING WRONG WITH THE REFERENCE SOLVER.XLS THAT I USE? CAN IT BE UPDATED?
    AGAIN i'VE OFFICE 2000

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: using variables in excel solver constraints problem!

    Try creating the model manually (as you did when you were recording the macro), and them save the model (Options > Save Model from the Solver menu) in a quiet place in the workbook.

    Then record a macro of loading the saved model, which restores the target cell, changing cells, and contraints.

  12. #12
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    I don't really understand what this will do. Could you clearify? Best regards

    Andy

  13. #13
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: using variables in excel solver constraints problem!

    1. Open Solver, enter the model manually, then do Options > Save Model, and save it someplace (it needs a few cells someplace on a worksheet).

    2. Start recording a macro. Open Solver, do Options > Load Model, load the saved model, run Solver, and stop recording.

    3. Use the macro recorded above to load the model and run Solver.

    I don't think there's anything I can add to that, Anders.

  14. #14
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    Hi,

    FIrst, here is the macro for creating the model

    Please Login or Register  to view this content.
    THen I samve the model, start a macro and then load the model

    THeis is the code output. As you can see the contratints are not there. Strange or?

    Please Login or Register  to view this content.
    Does the first piece of code work for you when put into a control button?
    a3=a1*a2

    thANLS FOR ALL THE HELP SO FAR. thIS PROBLEM IS SO STRANGE...

  15. #15
    Registered User
    Join Date
    12-22-2008
    Location
    Sweden
    Posts
    56

    Re: using variables in excel solver constraints problem!

    THe button can be pressed once when the correct values. If pressed again the decimal is not reaad by the solver and the 10,5 is reaad like 105...

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: using variables in excel solver constraints problem!

    Anders, I have no further suggestions, sorry.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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