suny morrisville-norwich campus- week 6 cita 130 advanced computer applications ii spring 2005 prof....

59
SUNY Morrisville- Norwich Campus-Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Post on 15-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

SUNY Morrisville-Norwich Campus-Week

6

CITA 130 Advanced Computer Applications II

Spring 2005Prof. Tom Smith

Page 2: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Objectives Questions from Last Week

Range Names and Macros

Solving Complex Problems with spreadsheets

Using Excel Solver

Page 3: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Microsoft Office Excel 2003

Tutorial 8 – Developing an Excel Application

Page 4: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Create and use range names It may be useful assign a name to a cell or

cell range. This is called a range name and allows you to

refer to the cell or range of cells by their name instead of their cell references. For example, you might assign a range name,

Expenses, to a group of cells that represent your expenses

When you want to calculate with those cells, you enter their Range Name in the formulas instead of the cell reference

You can later change the definition of the range names.

Page 5: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Creating a name using the Name box

Page 6: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Define Name dialog box

Page 7: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

View multiple range names

Page 8: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Using Range Names in a chart

Page 9: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Macro viruses and Excel's security features Because a macro is a program, a virus can be

attached to the macro. A macro is attached to a workbook and just opening the

workbook can cause the macro to be run If a macro has an attached virus, running the macro will

likely infect the computer being used to view the workbook

The first line of defense is to be sure you know where the workbook came from and whether the source is trustworthy.

Excel allows you to specify security for any workbook opened within Excel.

There are three levels of security: high, medium, and low.

Page 10: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Security dialog box

Page 11: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Create macros using the macro recorder One way to create a macro is to use the Excel macro

recorder. When you start the macro recorder, all of your

keystrokes are recorded and saved Once you have completed the keystrokes you want

recorded, you can close the macro Once the macro has been created, you can replay the

macro at anytime The macro can be stored in the workbook, making it

available whenever the workbook is opened. You can also store the macro in a new workbook or in

the Personal Macro workbook, which makes it available anytime Excel is running.

Page 12: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Record Macro dialog box

Page 13: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Macro dialog box

Page 14: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Edit and print a macro using the Visual Basic Editor All macros are small programs written in Visual

Basic for Applications (VBA), which is the programming language for Office 2003 applications.

You can create a new macro or edit an existing macro in the Visual Basic Editor. In the editor: You can see the VBA statements that make the macro

work You can view and edit the commands

The body of a macro is enclosed between the “Sub” and “End Sub” statements.

The body consists of the statements that will be performed when the macro is run.

Page 15: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The VBA editor Learning to program in VBA is an

extensive process. However, you can read through an

existing macro and get an idea of how the macro works.

You can print the macros so that you can review the printout.

Page 16: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Visual Basic editor

Page 17: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Update a macro in the VBA editor

Page 18: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Assign a macro to a keyboard shortcut You already learned how to invoke a

macro through the macro menu. Another option is to assign a shortcut key

to the macro. When the shortcut key is pressed, the

macro is run.

Page 19: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Assign a macro to a button You can create a button on the workbook

that will invoke a macro. To create a macro button, you must first

display the Forms toolbar. Then, select the button tool on the toolbar. The button is assigned to a particular

macro and, when it is pressed, the assigned macro runs.

Page 20: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Assign Macro Dialog Box

Page 21: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Add multiple macro buttons

Page 22: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Microsoft Office Excel 2003

Tutorial 10 – Using Solver For Complex Problems

Page 23: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Formulate a problem Goal Seek and Solver are Excel tools that can

help us solve complex, multi-variable problems. A typical multi-variable problem is optimizing the

mix of several different products to be manufactured, stocked, and/or sold by a factory or business.

Such problems deal with issues such as inventory, demand, display, space, and profit.

In order to solve such a problem in Excel, it is first necessary to create an Excel workbook showing all of the interrelated facts.

Page 24: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Income Analysis portion of sample worksheet

This figure shows an income analysis worksheet for a barbecue grill manufacturer.

This worksheet will be referenced in other slides in this presentation to illustrate solving complex problems with Excel.

Page 25: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Grill Parts Inventory portion of sample worksheet

This figure shows a grill parts inventory worksheet that will also be referenced in other slides in this presentation.

Page 26: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

An example problem The problem addressed in this example is to

optimize the profit that a grill manufacturing plant can make, by balancing the number of each kind of grill against inventory and revenue.

Note the following factors in the spreadsheets seen in the previous two slides: The cost, both in parts and labor, to produce each kind

of grill The selling price of each grill The total income The current inventory of all parts A chart of how many of each part are needed by each

grill type Most mix-optimizing problems will require this

type of information.

Page 27: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

A helpful formula tip The formula in cell I6 of the Inventory portion of

the worksheet (to calculate the count of the part named “Burner (Main)”) can be written in the form =$B$6*H21 +$C$6*I21 +$D$6*J21 +$E$6*K21.

In this way, it can be copied to the rest of the cells in the column.

This is better than writing a new formula for each count because it: Allows you to use the same formula for each part and

reduces the risk of data entry error Allows the possibility of someday changing the number

of parts used for a specific model without having to rewrite the formulas

Page 28: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Mix-optimizing problem considerations In every mix-optimizing problem, the

constraints or requirements must be defined.

In the problem under discussion, the solution must meet the following requirements: There must be enough of each kind of grill to

fill the current orders No further parts can be ordered or

manufactured, so no more grills can be manufactured once a part type is exhausted

The company wants a mix that will maximize profits

Page 29: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Perform what-if analyses Once you have a worksheet set up that

defines the problem, you can begin to do a what-if analysis.

A good way to begin is to enter some reasonable numbers, and see what happens.

This will also be a check to see if the worksheet is set up properly.

In our grill problem, the current orders would be a good starting place.

Page 30: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

An income analysis for an order

Page 31: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Now what-if? The order continued

Now the question is: How many more grills of each kind can be manufactured? What if we add 150 to the count of each model and order that many? This figure shows what happens with a guess—a what-if of 150 more of each model. The net income looks very good.

Page 32: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Recognizing a problem

Page 33: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Try to solve a problem using trial and error Returning to the last what-if analysis, entering a

count of 150 more than the current orders for each type of grill, you will remember that we used 15 too many of the parts called “Rack (Top)”.

You could check to see what models use this part, and reduce the count of one of them by 15. For example, let's reduce the count of Extended grills

from 225 to 210 This will make the parts inventory OK, and will reduce

the net income by $1,500 or so This looks like a good solution, but our problem is

to find the optimal solution, the optimal mix of grills that will yield the most net income.

Page 34: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Explore other order possibilities If you increase the number of Extended grills by

15 and decrease the number of Deluxe grills by 15, the solution is better, but is it the best?

Let's try increasing the number of Standard grills in the order (since they don't use top racks).

We could keep on trying different entries for the count of different models of grill, trying to come up with the best solution, but continuing to use this manual trial-and-error method is tedious, and could take a long time.

Fortunately, Excel has a tool that can help in trial-and-error problem solving.

Page 35: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Use Goal Seek to automate the trial-and-error process To automate the trial-and-error process,

Excel has a tool called Goal Seek. When you use Goal Seek, you specify the

result you want, and Goal Seek changes the value in an input cell to arrive at that result. For example, we have been changing the

number of each grill ordered (the inputs), and checking the net income (the result)

With Goal Seek, we specify the net income we want, and tell Goal Seek to change one of the inputs until it arrives at that goal.

Page 36: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Use Goal Seek In the worksheet for the optimal-mix problem

about grills, we want to see what inputs would give us a net income of 42,000.

To invoke Goal Seek, from the Tools menu, click Goal Seek.

This will bring up the Goal Seek dialog box. In that dialog box, you specify:

The cell to be set to some value The value you want to be in that cell The cell to change to accomplish the goal

Page 37: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Goal Seek dialog box

Page 38: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Understand the Goal Seek dialog box Goal Seek only allows you to enter one input cell

to change. If you read the text of the entire Goal Seek dialog

box as a sentence, it says, Set cell B21 to value 42000 by changing cell B6.

Keeping that sentence in mind will help you know what Goal Seek is going to try to do.

When you click OK, Goal Seek does its work. When it finds a solution, Goal Seek reports

success in a Goal Seek Status box.

Page 39: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Look for Goal Seek problems There are a couple of problems with this

solution seen in the previous slide. First of all, you cannot order 331.2887

Standard grills. Second, when you check the status of the

inventory, you see that there is a negative quantity in the Remaining column for the part called Igniter Button, which means you have exceeded the inventory for that part.

Page 40: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Fixing Goal Seek problems The first problem is caused by the fact that Goal

Seek does not differentiate between integer and real numbers.

Once Goal Seek gives you an estimate, you can manually change the number to the appropriate integer.

To fix the second problem, you can run Goal Seek again, this time specifying that cell J13 (the remaining igniter buttons) should be set to 0, by changing cell B4.

When you run Goal Seek with these values, the value displayed in B6 is 302.

If you click on cell B6, you will see that the real value is 302.000000000002. You should fix this by manually entering 302 in cell B6.

Page 41: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The final Goal Seek solution After making the changes shown in the previous

slide, check the inventory status, to see if there are any negative numbers.

The number of igniter buttons remaining is zero; this product mix uses them all.

Now, check the net income. It has fallen from $42,000 to just a little over $40,500, but we do have a workable solution that satisfies the first two constraints: All current orders can be filled The supply of parts has not been exceeded

Page 42: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Did Goal Seek provide the final answer? Goal Seek helped find a solution that worked, but

remember that our problem is to find the best solution—the one that yields the maximum net income.

We could do several trials using Goal Seek, and see which one of them is better, but we won't know that we have found the best one.

The only way to be absolutely sure that you have found the best solution using the trial-and-error method is to create all the solutions and then pick the best one.

In the current problem, there are thousands of different combinations, certainly more than we want to run.

Page 43: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Use Solver to find the best solution Excel has an add-in program called Solver. Check the Tools menu to see if Solver is installed

and activated on your machine. If it is, the word Solver will appear on the tools

menu. You can activate it by clicking Add-Ins on the

Tools menu. This will bring up a list of the add-in programs available

to activate Find Solver on the list, check its box, and then

click OK.

Page 44: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Install Solver If it is not installed, a dialog box that will

guide you in the installation of Solver. You will need your Microsoft Office 2003

CD to complete the installation. Once Solver is installed, you will not need

to install it again. It will be available on the Tools menu to

use any time you need to solve an optimal-mix type of problem.

Page 45: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Look for Solver on the Tools menu

Page 46: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Information required by Solver Solver needs four types of values that you will

enter into the Solver Parameter dialog box: 1. It needs the address of the target cell. 2. It needs to know what you want to do with the target

cell. You can ask Solver to set the target cell's value to the: greatest possible value the least possible value to a certain value that you enter

3. Solver needs to know which cells it can change to arrive at the desired result.

4. Solver needs to know what constraints have to be applied to the solution.

Page 47: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Solver Parameters dialog box

Page 48: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Add Solver constraints The next step is to enter the requirements, or

constraints. The first requirement is that the number of each

part cannot exceed the available supply of each part.

Since the counts of available parts are in column H, and the count of the parts used in the order are in corresponding places in column I, the constraint is that the value in cell I6 must be less than or equal to the value in cell H6, the value in cell I7 must be less than or equal to the value in cell H7, and so on.

Page 49: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Access the Add Constraint dialog box You can write this constraint in the Add Constraint dialog

box. Click Add in the Constraints section of the Solver

Parameters dialog box. This brings up the Add Constraint dialog box, which has

three boxes to enter values in. The first box asks for references to the cells in question, in our

case I6:I17 The second box lets you choose from several comparison

options; we will choose “=“ The third box asks you for the address of the constraining

cells, in our case H6:H17 Add additional constraints as needed for the problem being

solved.

Page 50: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

View the constraints

Page 51: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Add Constraint dialog box

Page 52: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Solver Results box

Page 53: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Create an answer report Once you have examined the optimal solution

created by Solver, you will want to create a report that captures the important facts about the solution.

Create an answer report from the Solver Results window: Set the changing cells (B6:E6) to zero Bring up Solver and notice that the parameters, changing cells,

and constraints are still just like you set them Click the Solve button and wait for the Solver Results window

to appear Check the Keep Solver Solution check box, and click on Answer

in the Reports box Solver creates the answer report and stores it in

a separate worksheet called “Answer Report”.

Page 54: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

A Solver Answer Report

Page 55: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Solver Answer Report sections Section one of the Solver Answer reports shown

in the previous slide is the title section, containing identifying information.

Section two is the Target Cell section. It shows the optimization goal (in this case, “Max”), the cell's address, the cell's name, the cell's value at the beginning of the Solver run, and the cell's value at the end of the run.

The third section is the Adjustable Cells section, containing the same information (address, name, start value, ending value) about all of the changing cells.

The fourth section is the Constraints section.

Page 56: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Configure Solver to best work with your data Solver is designed to use an iterative process:

It starts with an initial solution, and then does the problem over and over, using different values in the changing variables

When a change to a variable results in a better solution, Solver makes another change to the same variable in the same direction

When a change results in a worse solution, Solver does not make any more changes to that variable in that direction

Solver continues to make changes and re-run the problem, until it arrives at a solution that is not significantly better than the previous one.

At that point, Solver reports success.

Page 57: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Solver options you can set Max Time - Solver will stop when it has been looking for a solution for

this much time. If it has not yet found a solution, it will give you the option of stopping without an optimal solution or continuing for another time set.

Iterations - Solver will stop when it has done the problem this many times, even though it may not have arrived at a solution. Again, it will give you the option to stop or continue.

Precision - Solver continues to work until the constraints are satisfied within this precision For example, if the value in this box is 0.000001, and the constraint says J3 must equal 14, Solver will stop when the value in cell J3 is within 0.000001 of 14, that is, between 13.999999 and 14.000001.

Tolerance - similar to Precision, but for integer constraints. Solver stops when the answer is within this percent of the constraint value.

Convergence - Solver uses this to determine when a solution is significantly better than the previous one. If the change in the two solutions is less than or equal to this value, Solver will stop and declare that it has found a solution.

Assume Linear Model - if you know your problem can be solved with linear functions, you can speed up Solver by checking this box.

Page 58: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

The Solver Options dialog box

Page 59: SUNY Morrisville-Norwich Campus- Week 6 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith

Linear vs. non-linear functions A linear function is a function that can be written as the

sum of a series of variables, where each variable is multiplied by some constant.

A non-linear function involves using some mathematical operation other than summation.

Solver sometimes has problems arriving at a solution to non-linear problems, simply because in a non-linear problem, there may be many avenues that Solver could travel to find solutions, and it is not always possible to determine which of these directions is the best.

The rest of the choice boxes in the Solver Options dialog box have to do with helping Solver solve non-linear problems.

Generally, these options are for the advanced user.