Lab 8 Solver In VBA ► Review – Solver Add-in In Excel ► Solver Add-in In VBA.

Slides:



Advertisements
Similar presentations
Solving LP Problems in a Spreadsheet
Advertisements

Wyndor Example; Enter data Organize the data for the model on the spreadsheet. Type in the coefficients of the constraints and the objective function.
McGraw-Hill/Irwin ©2008 The McGraw-Hill Companies, All Rights Reserved TECHNOLOGY PLUG-IN T4 PROBLEM SOLVING USING EXCEL Goal Seek, Solver & Pivot Tables.
Decision Analysis Tools in Excel
Using Macros and Visual Basic for Applications (VBA) with Excel
Introduction to Management Science
Microsoft Office 2007 Excel Chapter 8 Formula Auditing, Data Validation, and Complex Problem Solving.
SOLVING LINEAR PROGRAMS USING EXCEL Dr. Ron Lembke.
Linear Programming Excel Solver. MAX8X 1 + 5X 2 s.t.2X 1 + 1X 2 ≤ 1000 (Plastic) 3X 1 + 4X 2 ≤ 2400 (Prod. Time) X 1 + X 2 ≤ 700 (Total Prod.) X 1 - X.
Using the Visual Basic Editor Visual Basic for Applications 1.
Formula Auditing, Data Validation, and Complex Problem Solving
Computational Methods for Management and Economics Carla Gomes Module 4 Displaying and Solving LP Models on a Spreadsheet.
COMPREHENSIVE Excel Tutorial 10 Performing What-If Analyses.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
456/556 Introduction to Operations Research Optimization with the Excel 2007 Solver.
START EXCEL BUILD OR RETRIEVE YOUR OPTIMIZATION MODEL SAVE YOUR WORKBOOK!! CHOOSE “Solver…” IN THE “Tools” MENU SPECIFY IN SOLVER DIALOG BOX: 1.CELL TO.
Visual Basic Chapter 1 Mr. Wangler.
Spreadsheet Modeling of Linear Programming (LP). Spreadsheet Modeling There is no exact one way to develop an LP spreadsheet model. We will work through.
University of Toronto at Scarborough © Andria Hunter, Kersti Wain-Bantin CSCA01 VBA-3 1 Lecture Outline Variable Scope Calling another subprogram Programming.
Introducing Access Lesson 1. Objectives Start Access and explore the Database window Explore database objects Enter, edit, and delete records in a datasheet.
Introduction to Engineering Computing GEEN 1300 Lecture 7 15 June 2010 Review for midterm.
Chapter 19: Solver Re-Visited Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
Linear Programming: Basic Concepts
We can make Product1 and Product2. There are 3 resources; Resource1, Resource2, Resource3. Product1 needs one hour of Resource1, nothing of Resource2,
Linear Programming McGraw-Hill/Irwin Copyright © 2012 by The McGraw-Hill Companies, Inc. All rights reserved.
Appendix B A BRIEF TOUR OF SOLVER Prescriptive Analytics
Linear Programming Copyright © 2015 McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill.
Chapter 19: The Solver Re-Visited Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University Name.
CTS130 Spreadsheet Lesson 19 Using What-If Analysis.
Goal Seek and Solver. Goal seeking helps you n Find a specific value for a target cell by adjusting the value of one other cell whose value is allowed.
Chapter 3 The Visual Basic Editor. Important Features of the VBE Alt-F11 will open the Visual Basic Editor. The Code window is to the right, Project Explorer.
Copyright © 2008 Pearson Prentice Hall. All rights reserved Exploring Microsoft Office Excel 2007 Chapter 8 What-if Analysis Robert Grauer, Keith.
Lab 3 Solver Add-In In Excel ► Lab 2 Review ► Solver Add-in Introduction ► Practice Solver following Instructor » Saferly Inc.
Decision Making Using Excel
DAY 9: MICROSOFT EXCEL – CHAPTER 6 Sravanthi Lakkimsetty Sept 16, 2015.
ENGM 631 Optimization Using Solver. Sec. 3.1Alt. Model Max Z = 3X 1 + 5X 2 s.t. X 1 < 8,000 X 2 < 6,000 3X 1 + 4X 2 < 36,000 X 1 > 0 X 2 > 0.
McGraw-Hill/Irwin Copyright © 2009 by The McGraw-Hill Companies, Inc. All Rights Reserved. Supplement 6 Linear Programming.
Linear Programming II. George Dantzig 1947 Narendra Karmarkar Pioneers of LP.
Chapter 15: Sub Procedures and Function Procedures Spreadsheet-Based Decision Support Systems Prof. Name Position (123) University.
1 Visual Basic for Applications - VBA IE What is VBA?  VBA comes with Office u Objects (e.g. of Excel) are exposed for use by VBA u Visual Basic.
Linear Programming McGraw-Hill/Irwin Copyright © 2012 by The McGraw-Hill Companies, Inc. All rights reserved.
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
Excel Functions. Part 1. Introduction 2 An Excel function is a formula or a procedure that is performed in the Visual Basic environment, outside the.
COMPREHENSIVE Excel Tutorial 12 Expanding Excel with Visual Basic for Applications.
Solving Linear Optimization Problems Using the Solver Add-in.
Formula Auditing, Data Validation, and Complex Problem Solving
Exploring Microsoft Office Exploring Excel Appendix C
Setting up Solver Add-in for Excel
Session 9.
Excel Tutorial 8 Developing an Excel Application
Solver & Optimization Problems
Excel Solver IE 469 Spring 2017.
Excel Solver.
Excel Solver IE 469 Spring 2018.
Wyndor Example; Enter data
Solver via VBA IE 469 Fall 2017.
Exploring Microsoft Excel
Using WinQSB to solve Linear Programming Models
Solver via VBA IE 469 Spring 2018.
Excel Solver IE 469 Fall 2018.
Excel: Solver Participation Project
Solver via VBA IE 469 Spring 2018.
Linear Programming Excel Solver.
Solving Linear Optimization Problems Using the Solver Add-in
Excel Solver IE 469 Spring 2019.
BUS-221 Quantitative Methods
Solver via VBA IE 469 Spring 2019.
Presentation transcript:

Lab 8 Solver In VBA ► Review – Solver Add-in In Excel ► Solver Add-in In VBA

Review: Using Solver in Excel Describe the optimization model on an Excel worksheet Open the Solver dialog box in Excel (Tools/Solver) Specify the major items in the Solver dialog box –Set Target Cell: the cell that contains the formula for the objective function –Equal To: the type of the objective function –By Changing Cells: the cells set to contain the values of the decision variables –Subject to the Constraints: the adding of the constraints –Options: Assume Linear Model Assume Non-Negative –Reset All: clears all previous settings Run the Solver

Using Solver with VBA Code Describe the model on an Excel worksheet Write code using Solver functions to specify the model. The major Solver functions include: –SolverReset –SolverOk –SolverAdd –SolverOptions –SolverSolve Run the code

Solver Functions in VBA Frontline Systems has written several VBA functions that allow developers to operate Solver “behind the scenes” with code These functions enable you to specify the model (target cell, changing cells, and constraints) and set options, etc. All the Solver functions begin with the word “Solver” Check the Web site for detailed help on all Solver functions

Setting a Reference To use the Solver functions in an application, you need to set a Reference to the Solver Add-in in VBE. Set the reference with the Tools/References menu item in VBE. In a long list of possible libraries of code, check “Solver.xla” or “Solver” The reference will then appear in the Project Explorer window.

SolverReset Function To reset the Solver, use this line: SolverReset It clears all previous settings.

SolverOK Function It does three things: –Identifies the target cell (Objective function) –Specifies whether it is a maximization or minimization problem –Identifies the changing cells Syntax (it takes three arguments): SolverOK SetCell:=, MaxMinVal:=, ByChange:= If it is a maximization problem: MaxMinVal = 1 minimization problem : MaxMinVal = 2 Example: SolverOK SetCell:= Range(“E12”), MaxMinVal:=1, _ ByChange:=Range(“C9:D9”)

SolverAdd Function (1) This function adds a new constraint each time it is called. Syntax: SolverAdd CellRef:=, Relation:=, FormulaText:= –CellRef is a reference to a cell or a range of cells on the active worksheet that forms the left hand side of the constraint. –Relation specifies the arithmetic relationship between the left and right sides of the constraint. More specifically it has the following values: RelationRelationship 1 <= 2 = 3 >= 4the left hand side has integer value(s) 5the left hand side has binary value(s) (If the Relation equals to 4 or 5, the constraint has no right hand side.) –FormulaText is the right hand side of the constraint, and it can be a number or a reference to a range of cells.

SolverAdd Function (2) Example: SolverAdd CellRef:=Range(“D14”), Relation:=1, _ FormulaText:=“F14” SolverAdd CellRef:=Range(“D15”), Relation:=1, _ FormulaText:=“F15” SolverAdd CellRef:=Range(“D16”), Relation:=3, _ FormulaText:=“F16” SolverAdd CellRef:=Range(“D17”), Relation:=3, _ FormulaText:=“F17” Or you can add several constraints together if they are of the same relations: SolverAdd CellRef:=Range(“D14:D15”), Relation:=1, _ FormulaText:=“F14:F15”

SolverOptions Function It allows you to set any of the options and is equivalent to click the Options button in the Solver dialog box in Excel. Syntax: SolverOptions (list of options separated by commas) The two most frequently used options are the Assume Linear Model and Assume Non-Negative options. Example: SolverOptions AssumeLinear:=True, AssumeNonNeg:=True

SolverSolve Function It is equivalent to click the Solve button in the usual Solver dialog box to run the solver. Syntax: SolverSolve [UserFinish:=] –UserFinish: If it is True, the solver results dialog box will not appear; if it is False or omitted, Solver displays the standard Solver results dialog box, allowing the user to keep or discard the final solution values, and optionally produce reports. The SolverSolve function returns an integer value that indicates Solver’s success. If this integer is 0 (or 1, 2), it means successful; if it is 4, the solver did not converge; if it is 5, there is not a feasible solution. Example: SolverSolve UserFinish:=True Example of using the returned value: If SolverSolve(UserFinish:=True) = 5 Then _ MsgBox “There are no feasible solutions.”

Summary: Solving the Product Mix Example Putting the SolverReset, SolverOK, SolverAdd, SolverOptions, and SolverSolve together, we can write a sub to solve the product mix example: Sub SaferlySolver() SolverReset SolverOK SetCell:=Range("E12"), MaxMinVal:=1, _ ByChange:=Range("C9:D9") SolverAdd CellRef:=Range("E15:E16"), Relation:=1, _ FormulaText:="G15:G16" SolverOptions AssumeLinear:=True, _ AssumeNonNeg:=True If SolverSolve(UserFinish:=True) = 5 Then _ MsgBox " There are no feasible solutions. " End Sub

Add Buttons To Run VBA Code You can actually add form buttons on the Excel worksheet so that users can simply click the Buttons to run the VBA code: –Anywhere at the Excel toolbar, right click to bring up a list of toolbars available and select Forms tools –Click on the fourth control – Button –On the Worksheet – place and draw a button –Assign the Solver Sub to this button –Change the button label to “Run Solver” –Write another short Sub in VBE to clear the results in Range(“C9:D9”); assign this macro to a new button with button label “Clear Results” –Now click on the two buttons to clear the results and run the solver in Excel!

Assignment 2 Solve the Krazy Krakers’ spreadsheet model with VBA code. 1) Consider the set up of the Krazy Kracker problem from lab 2; 2) Write code with VBA Solver functions to solve the Linear Programming (LP) model. 3) Within your codes, check to see whether there are feasible solutions. If there are not, display an appropriate message. 4) Add two Form buttons on the Worksheet to run the solver and clear the results. (Notes: Don’t forget to add the Reference in VBE before running your Solver code)

Note You are required to have both assignments for this lab stay in one excel file. Data and model of the two assignment should be put in two separate worksheets Create buttons for each assignment.