SHA 6050 Solver and VBA Lab

Similar documents
Portfolio Optimization

Word 2010: Mail Merge to with Attachments

Writing Macros in Microsoft Excel 2003

Migrating to Excel 2010 from Excel Excel - Microsoft Office 1 of 1

Microsoft Excel 2013: Macro to apply Custom Margins, Titles, Gridlines, Autofit Width & Add Macro to Quick Access Toolbar & How to Delete a Macro.

Using Microsoft Excel to build Efficient Frontiers via the Mean Variance Optimization Method

1. a procedure that you perform frequently. 2. Create a command. 3. Create a new. 4. Create custom for Excel.

Tommy B. Harrington 104 Azalea Drive Greenville, NC

Working with Macros and VBA in Excel 2007

USING EXCEL 2010 TO SOLVE LINEAR PROGRAMMING PROBLEMS MTH 125 Chapter 4

Excel & Visual Basic for Applications (VBA)

Call Centre Helper - Forecasting Excel Template

Programming in Access VBA

EXCEL FINANCIAL USES

Solving Linear Programs in Excel

Excel 2007 Basic knowledge

Basic Pivot Tables. To begin your pivot table, choose Data, Pivot Table and Pivot Chart Report. 1 of 18

Excel 2010: Create your first spreadsheet

To create a histogram, you must organize the data in two columns on the worksheet. These columns must contain the following data:

Construction Administrators Work Smart with Excel Programming and Functions. OTEC 2014 Session 78 Robert Henry

BulkSMS Text Messenger Product Manual

Explore commands on the ribbon Each ribbon tab has groups, and each group has a set of related commands.

Tutorial: Using Excel for Linear Optimization Problems

Automate tasks with Visual Basic macros

VBA PROGRAMMING FOR EXCEL FREDRIC B. GLUCK

What is Microsoft Excel?

Using Excel for Business Analysis: A Guide to Financial Modelling Fundamentals

Microsoft Excel 2013 Tutorial

WEBFOCUS QUICK DATA FOR EXCEL

1. Linking among several worksheets in the same workbook 2. Linking data from one workbook to another

Report Generator Manual

Outlook Quick Steps & Rules

Solving Systems of Equations Using Mathcad Charles Nippert Solving A System of Equations By Symbolically Figure 1 After Step 1

Organizing and Managing

Excel Pivot Tables. Blue Pecan Computer Training Ltd - Onsite Training Provider :: :: info@bluepecan.co.

Macros in Word & Excel

Excel Modeling Practice. The Svelte Glove Problem Step-by-Step With Instructions

EXCEL Tutorial: How to use EXCEL for Graphs and Calculations.

Microsoft Access 2010 Part 1: Introduction to Access

Excel Programming Tutorial 1

Adding Comments in Microsoft Excel 2003

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

Quick Start Guide. Highly customizable automated trading Automate your trades according to rules and models you create.

RIT Installation Instructions

Instructions Budget Sheets

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

Excel Reports User Guide

Microsoft Excel 2013: Using a Data Entry Form

MS WORD 2007 (PC) Macros and Track Changes Please note the latest Macintosh version of MS Word does not have Macros.

Excel Reports and Macros

Chapter 4 Displaying and Describing Categorical Data

ECDL. European Computer Driving Licence. Spreadsheet Software BCS ITQ Level 2. Syllabus Version 5.0

CREATING FORMAL REPORT. using MICROSOFT WORD. and EXCEL

Step 2: Headings and Subheadings

Creating tables of contents and figures in Word 2013

Excel. Microsoft Office s spreadsheet application can be used to track. and analyze numerical data for display on screen or in printed

Highline Excel 2016 Class 26: Macro Recorder

Using Mail Merge to Create Form Letters and Labels

Excel macros made easy

This Skill Builder demonstrates how to define and place sketched symbols in drawings.

Microsoft Excel 2010 Training. Use Excel tables to manage information

EXCEL VBA ( MACRO PROGRAMMING ) LEVEL SEPTEMBER AM-5.00PM MENARA PJ@AMCORP PETALING JAYA

Microsoft Office Access 2007 Basics

Instructions to operating forms created in MSWord and Excel

Mail Merge Creating Mailing Labels 3/23/2011

Gantt Chart/Diagram Excel Template User Guide

Excel Basics By Tom Peters & Laura Spielman

warpct.com Working with MS Excel 2003 Workbook courseware by WARP! Computer Training

How to Create a Spreadsheet With Updating Stock Prices Version 3, February 2015

Table Of Contents. iii

Excel Reporting with 1010data

Microsoft Excel 2010 Part 3: Advanced Excel

Excel Spreadsheets: Getting Started

INTRODUCTION TO DESKTOP PUBLISHING

USC Marshall School of Business Marshall Information Services

Microsoft. Outlook ADVANCED FEATURES AND FUNCTIONS

Advanced Excel Charts : Tables : Pivots : Macros

Produced by Flinders University Centre for Educational ICT. PivotTables Excel 2010

Database Backup Datacolor Match Pigment and Datacolor Tools

Excel & Visual Basic for Applications (VBA)

WHAT S NEW IN MS EXCEL 2013

Advanced Presentation Features and Animation

Microsoft Excel 2013: Headers and Footers

Mail Merge. Course Description. Objectives: Design a Main Document. Design a Data Source. Directories. Merge the Main Document with the Data

Monthly Payroll to Finance Reconciliation Report: Access and Instructions

Microsoft Project 2013

Linear Programming Refining Transportation

Designed by Jason Wagner, Course Web Programmer, Office of e-learning ZPRELIMINARY INFORMATION... 1 LOADING THE INITIAL REPORT... 1 OUR EXAMPLE...

Chapter 9 Creating Reports in Excel

Basic Microsoft Excel 2007

Performing Simple Calculations Using the Status Bar

Summary of important mathematical operations and formulas (from first tutorial):

SPV Reporting Tool VBA Code User Guide. Last Updated: December, 2009

Microsoft Excel 2010 Charts and Graphs

Using EXCEL Solver October, 2000

Microsoft Excel Basics

Formatting Formatting Tables

Manual. OIRE Escuela de Profesiones de la Salud. Power Point 2007

Transcription:

SHA 6050 Solver and VBA Lab In this lab you will be using macros to run Excel Solver. You will also use some basic tools in Visual Basic. Open 605_LP_Solver_Lab.xls. You will find a typical linear programming model. The usual template to input into Solver has already been set up. You will create a macro to record the actions that you perform to run Solver so that the next time that you want to run Solver, all you ll have to do is click a button. CLASSIC RM Setup Open the RM sheet here s what you ll see. Part A: Decision Variables 1 2 3 1 2 3 1 2 3 Date 99 99 99 129 129 129 159 159 159 10/3 10/4 10/5 10/6 10/7 10/8 10/9 10/10 10/11 10/12 10/13 10/14 10/15 10/16 Part E: Expected Pickup Date 99-1 99-2 99-3 129-1 129-2 129-3 159-1 159-2 159-3 10/3 10/4 10/5 10/6 10/7 10/8 10/9 10/10 10/11 10/12 10/13 10/14 10/15 10/16 Hotel Capacity: 200 Part B: Rooms Sold Part C: Rooms Available Part D: Total Revenue Daily Revenue SOLVER and VBA 1

Step 1: Enter the formulas: Part A: Decision Variables: No formulas, this is what you will solve for. Part B: Rooms Sold: The formula accounts for the number of arrivals AND the number of stayovers. Go to Cell K4 and enter the formula: =SUM(B4:J4) Go to Cell K5 and enter the formula: =SUM(B5:J5,C4:D4,F4:G4,I4:J4) Go to Cell K6 and enter the formula: =SUM(B6:J6,C5:D5,F5:G5,I5:J5,D4,G4,J4) Fill down. Part C: Rooms Available: To calculate the number of rooms available, we must subtract the number of reservations on hand from the number of rooms in the hotel. Assume our hotel has 200 rooms. On RM sheet, Cell L4, enter the formula: =MAX(0,$M$1-SUM(ROH!D4:L4)) Since we must account for stayovers, the formulas for the remaining days will be slightly different. Go to Cell L5 and enter the formula: =MAX(0,$M$1-SUM(ROH!D5:L5,ROH!E4:F4,ROH!H4:I4,ROH!K4:L4)) Finally, go to Cell L6 and enter the formula: =MAX(0,$M$1-SUM(ROH!D6:L6,ROH!E5:F5,ROH!H5:I5,ROH!K5:L5,ROH!F4,ROH!I4,ROH!L4)) Fill down. SOLVER and VBA 2

Part D: Total Revenue: To calculate the Total Revenue, you must first calculate the Daily Revenue. Go to Cell M4 and enter the formula: =SUMPRODUCT($B$2:$J$2,$B$3:$J$3,B4:J4) Fill down. To calculate the Total Revenue, you must sum the Daily Revenues. Go to cell M18 and enter the formula: =SUM(M4:M17) Part E: Expected Pickup: These numbers are the same as the numbers that are in the ROH sheet. Go to Cell B21 of the Ours sheet and enter the formula: =MAX(0,ROH!M4) Fill down and right Step 2: Set up the Solver problem. Maximize: $M$18 By Changing Cells: $B$4:$J$17 Subject to: Demand constraints (can t sell more than demanded) $B$4:$J$17<=$B$21:$J$34 Capacity constraints (can t sell more rooms than available). $K$4:$K$17<=$L$4:$L$17 Step 3: Options: Assume Linear Model and Assume Non-Negative Step 4: Solve NOW Let s use VBA to build and control our MODEL 1. Record a new macro SOLVER and VBA 3

Developers-Macro-Record New 2. Type in a name for the macro, "solver1 and hit the enter key. 3. Set up the Solver as you normally would (Excel is recording every move you make so don't do anything extra). Data-Solver select Reset All in Solver before setting up the model. Build the Solver model again as above 4. Solve 5. Generate Sensitivity Report 6. Copy and Paste the Shadow Prices to the Restrictions tab 7. Delete the Sensitivity Report sheet. Right Click the Sheet Tab - Delete Delete 8. Stop recording the macro. Click on the square box in the floating macro box OR Go to Developer-Macro-Stop Recording Macro Now every time you run the macro, it will automatically update your shadow prices. Then you can link rate and availability restrictions to these cells so that they can be updated automatically at the same time. Return to the Visual Basic Editor to see how your code has changed. There are some additional changes that you will have to make to the code for true automation of the task in the future. These are as follows: Every time a sensitivity report is created, the number assigned to the report is incremented by one. For example, the next time you run the macro, the sensitivity report will be called "Sensitivity Report 2" instead of "Sensitivity Report 1" and the macro will give you an error message since it cannot find "Sensitivity Report 1". To avoid this problem, make the following change to the code: Replace Sheets("Sensitivity Report 1").Select with Sheets(1).Select NOTE: This change needs to be made at 2 places in the macro. The number in the parentheses indicates the order of the sheets (i.e. 1 means the first sheet). Since the sensitivity report is always inserted immediately before the current worksheet, it will be always the first sheet. Therefore, Sheet(1) will always refer to the sensitivity report. The macro does not automatically record the selection of the sensitivity report. To select the sensitivity report, replace "SolverSolve" with the following: SolverSolve userfinish:=true SolverFinish KeepFinal:=1, ReportArray := Array(2) To avoid the alert dialog box when deleting the sensitivity report, add the following directly above ActiveWindow.SelectedSheets.Delete : SOLVER and VBA 4

Application.DisplayAlerts = False Create a Button to Run the Macro You can use a button to run the macro rather than going to the Tools menu and choosing Run Macro. In order to do this: 1. Click on the Button icon on the Forms toolbar and place a button anywhere on the worksheet. 2. The Assign Macro dialog box will appear. Choose solver1 and click OK. 3. Rename the button as solver1 then click somewhere outside of it to deselect it. 4. Click the button at any time and Solver will run just as you recorded it in the macro. NOTE: IF YOUR CODE WILL NOT RUN, IN THE VB EDITOR (ALT-F11) UNDER TOOLS, REFERENCES, make sure that SOLVER is selected from the list. Again VBA is fun, please come see me if you have troubles, don t spend too much time banging your head against the wall. JUST IN CASE: THE CODE Sub SOLVER_RUN() ' ' SOLVER_RUN Macro ' THIS MACRO RUNS OUR SOLVER MODEL ' SolverReset SolverOk SetCell:="$M$18", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$4:$J$17" SolverAdd CellRef:="$B$4:$J$17", Relation:=1, FormulaText:="$B$21:$J$34" SolverAdd CellRef:="$K$4:$K$17", Relation:=1, FormulaText:="$L$4:$L$17" SolverOk SetCell:="$M$18", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$4:$J$17" SolverOptions MaxTime:=100, Iterations:=100, Precision:=0.000001, AssumeLinear _ :=True, StepThru:=False, Estimates:=1, Derivatives:=1, SearchOption:=1, _ IntTolerance:=5, Scaling:=False, Convergence:=0.0001, AssumeNonNeg:=True SolverOk SetCell:="$M$18", MaxMinVal:=1, ValueOf:="0", ByChange:="$B$4:$J$17" SolverSolve userfinish:=true SolverFinish KeepFinal:=1, ReportArray:=Array(2) SOLVER and VBA 5

Sheets("Sensitivity Report 1").Select Range("E139:E152").Select Selection.Copy Sheets("Restrictions").Select Range("B3").Select ActiveSheet.Paste Sheets("Sensitivity Report 1").Select Application.CutCopyMode = False Application.DisplayAlerts = False ActiveWindow.SelectedSheets.Delete Application.DisplayAlerts = True End Sub SOLVER and VBA 6