Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6545651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:36:43+00:00 2026-05-25T11:36:43+00:00

I am trying to add some new constraints to my excel VBA solver solution

  • 0

I am trying to add some new constraints to my excel VBA solver solution and am getting some odd behavior when I run the code. I want to do the following for a minimization problem and am having some trouble:

The two levers that are being adjusted must be <= 35%, however when I add the constraint:

SolverAdd CellRef:="$C$39", Relation:=2, FormulaText:=".35"
SolverAdd CellRef:="$C$40", Relation:=2, FormulaText:=".35"

They automatically set themselves at 35% when the idea is for these to be as low as possible. Without this constraint the cells do set themselves below 35% for the problems I’m validating against, so I know the optimum solution is below 35%.

Also I was wondering if there is a way to make sure that a) the cells are optimized in increments of 5%, and that the ending value does not include decimals. i.e. 10.00% instead of 10.23%

Sorry for the long winded question, I appreciate any help I get.

Here is the full code:

    Private Sub CommandButton2_Click()

Dim i As Integer


i = 2

For i = 2 To 5

   Range("$C$14").Value = Application.Workbooks("test_model_2.xls").Worksheets("All Models").Cells(i, 2).Value
    SolverReset
    SolverAdd CellRef:="$F$70", Relation:=3, FormulaText:="5000"
    SolverAdd CellRef:="$C$39", Relation:=2, FormulaText:=".35"
    SolverAdd CellRef:="$C$40", Relation:=2, FormulaText:=".35"
    SolverOk SetCell:="$F$70", MaxMinVal:=2, ValueOf:="0", ByChange:="$C$39:$C$40"
    SolverSolve True
   MsgBox "i is:" & i

Next i

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T11:36:43+00:00Added an answer on May 25, 2026 at 11:36 am

    See: http://msdn.microsoft.com/en-us/library/aa272233(v=office.10).aspx

    You’re using relation:=2, which equates to “=”. You should be using 1 (<=)

    As for getting your solution to the nearest 0.05, just set up some other cells which feed into the “percent” cells, and have them constrained to integer values.

    Eg:

    A1 = 7           (set solver to change this, and constrain to integer)
    B1 = A1 * 0.05   (your percent cell, constrain to <=0.35)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to JQuery. I am trying to add some code in my
I'm making Rails 3.1.1 app and trying to add some jQuery code to it.
I'm creating some new files and am trying to add them but when I
I'm trying to extend Page class to add some new functionality (ease of use
I am trying to add some functionality to my posts/new page when it loads,
Im trying to add some short file names to a Wise installer to fix
I am trying to add some custom build steps to my headless build process
I'm trying to add some accessibility for screen readers into a Flash application, and
I'm trying to add some security to my ASP.NET 1.0 MVC app (VB), but
So I'm trying to add some ability to my project to allow user-defined properties

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.