Microsoft Excel Notes

advertisement
Microsoft Excel
Models and Functions
ACCT 5329
Microsoft Excel Models and Functions

You will need to download the ExcelExample.xslx file
from WebCT to work through the examples in this
presentation
Microsoft Excel Models
What-If and Goal Seek
What-If Analysis


Relies on the ease of copying your model and changing
various input variables
Least formal method for solving a problem



Copy the input variables and formulas multiple times
Then vary input variables until you reach a suitable solution
See the What-If-GoalSeek tab in the Excel worksheet
Creating a Two-Variable What-If Table





Enter a formula that points to at least two variable cells in
the upper left corner of the table.
Along the left column of the table, enter various values
for one of the inputs.
Along the top row of the table, enter various values for
the other input variable.
Select the entire table.
From the Data Ribbon,
select Data Tools,
What-If Analysis,
Data Table
Creating a Two-Variable What-If Table

In the Data Table dialog box, enter a row input cell and a
column input cell.

Select the Term cell (B15) as the row input cell
Select the Price cell (B14) as the column input cell
Click OK. Excel will fill in the monthly payment in the
table using the price in the column and the terms in the
top row.


Apply Conditional Formatting to What-If Table



Highlight just the data in the What-If Table.
From the Home ribbon,
select the Conditional
Formatting drop-down box,
then Highlight Cell Rules,
then Between
Type in your values in the dialog box, select the highlight
type from the drop-down box and Click OK.
Goal Seek


Used to quickly and easily hone in on a ‘target’ value
Steps using the Car Purchase Example on the What-IfGoalSeek tab
1.
2.
Select the answer cell. In this example, it would be the
payment in Cell B40
From the Data Tools group of the Data ribbon, select the
What If Analysis drop-down and then choose Goal Seek. The
Goal Seek dialog box appears as shown below
Goal Seek Steps
In the Goal Seek dialog, indicate that you want to set
the answer cell to a particular value by changing a
particular input cell.
3.



In this example, you want to set Cell B40 to the value of
$695 by changing Cell B37. Excel quickly tries to hone in on
a value. When Excel gets to within a penny of the value, the
Goal Seek Status dialog appears as shown below
This dialog reports that it was trying to
reach a target value of $695 and was able
to reach that value.
The worksheet then shows the proposed
price of $36,828.54 in Cell B37.
Goal Seek Not For All Problems

Goal Seek needs a clear mathematical relationship
between the starting and ending cells
Microsoft Excel Functions
VLOOKUP
VLOOKUP



Vertical lookup – one of the most powerful and most
used functions in Excel
VLOOKUP allows you to perform the equivalent of a join
operation in a database
VLOOKUP tab in the examples worksheet
VLOOKUP

Setting up the Lookup Table:
1.
2.
3.
Build a table showing the scores where the grading scale
changes from one grade to the next
The table has to be sorted in ascending order
Make sure your lookup values are in the leftmost column of
your lookup table as Excel searches the first column for the
appropriate value
VLOOKUP

Entering the VLOOKUP formula
We are looking up the Grade, so the formula will be entered
into the cells in column C
Syntax
1.
2.

3.
4.
5.
6.
VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
The value we are looking up is the student score in column B, so in
Cell C2 enter =VLOOKUP(B2,
The 2nd argument is the lookup table, so enter the range making
sure to use an absolute range (press F4) or use a predefined range
name. =VLOOKUP(B2, $E$2:$F$6,
The 3rd argument specifies which column of the lookup table
should be returned. =VLOOKUP(B2, $E$2:$F$6, 2
The 4th argument is TRUE or simply omitted as we are using the
sorted range variety of lookup. =VLOOKUP(B2, $E$2:$F$6, 2)
VLOOKUP




Using VLOOKUP with FALSE to find an exact value
Use the second table on the VLOOKUP tab
The manager wants to see the sales rep names on the
report
Create the VLOOKUP function to lookup the Sales Rep
name
VLOOKUP

To recap,

Two versions of the VLOOKUP formula that behave very
differently:



VLOOKUP with FALSE as the fourth parameter looks for an exact
match, and
VLOOKUP with TRUE as the fourth parameter looks for the closest
(lower) match.
The lookup table must sorted using the TRUE parameter, but in the
FALSE version the table can be in any sequence
VLOOKUP


Using VLOOKUP to match two lists
Use table on VLOOKUP2 tab
VLOOKUP




Create the VLOOKUP formula to compare the two lists
Hint: The formula in Cell D5 should look at the value in
Cell C5 to see if that person is in the approved list.
For any cells in Column D that contain a name, it means
that the person was on the Approved Customer List. If
the result is #N/A, you know that a sales was made to a
non-approved customer
Create a VLOOKUP function to find approved customers
that have made a purchase
Microsoft Excel Functions
COUNTIF, SUMIF, AVERAGEIF
SUMIF, COUNTIF, AVERAGEIF

SUMIF(range, criteria, sum_range)


COUNTIF(range, criteria)


Adds the cells specified by the given criteria
Counts the number of cells within a range that meet the given
criteria
AVERAGEIF(range, criteria, [average_range])

Returns the average (arithmetic mean) of all the cells in a range
that meet the given criteria
SUMIF, COUNTIF, AVERAGEIF

Using the table in the ___IF tab in the example
worksheet, complete the count, total, and average
columns for each division
SUMIFS, COUNTIFS, AVERAGEIFS

In Excel 2007, new versions of SUMIF, COUNTIF, and
AVERAGEIF that can handle unlimited multiple conditions

SUMIFS(sum_range, criteria_range1, criteria1[,criteria_range2, criteria2…])
COUNTIFS(range1, criteria1[,range2, criteria2…])
AVERAGEIFS(average_range, criteria_range1, criteria1[,criteria_range2,
criteria2…])


SUMIFS, COUNTIFS, AVERAGEIFS

Using the table in the ___IFS tab in the example
worksheet, complete the count, total, and average
columns by region and division
Microsoft Excel
Pivot Tables
Pivot Tables



A data summarization tool
Best created from transactional data
Users can create any number of views of the data such as:







Breakdown of sales by product
Sales by month, this year versus last year
Percentage of sales, by customer
Customers who bought product XYZ in the Midwest region
Sales by product, by month
Top five customers, with products
etc.
Pivot Tables

Rules for Pivot Table data:







Make sure each column has a unique one-cell heading
Do not allow blank cells in a numeric column (use zeros
instead)
Do not use blank rows or blank columns
Make sure no summary data is missing
Remove any embedded totals from the data
Remove any formulas from the data
Data with month (or years) spread across many columns will
need to be converted to a columnar format
Creating a Pivot Table




On the PivotTable tab in the example spreadsheet, Select
one cell in the data.
From the Insert ribbon, click the PivotTable icon in the
Tables group.
Excel displays the Create PivotTable dialog box. Excel’s
IntelliSense should have chosen the correct range for the
data.
Choose to place the PivotTable
in a New Worksheet.
Creating a Pivot Table

The PivotTable Field
List box:


Can be toggled on
and off by using the
Show/Hide – Field
List in the Options
ribbon (see next
slide for exact
location)
The drop-down icon
offers five different
views of the Field
List box
Creating a Pivot Table



To create the pivot table, simply use the PivotTable Field
List box to check which fields to include in the table.
Excel makes fairly intelligent guesses based on the field
type and build a passable table.
You can then make adjustments to perfect the table.
Creating a Pivot Table





Using ExcelExamples.xlsx, create a Pivot Table.
In the PivotTable Field List box, check the Region,
Product, and Revenue boxes.
Notice that Excel adds a new field called Sum of Revenue
to the ∑ Values section of the Field List box because the
field is numeric.
Excel moves Region and Product to the Rows Labels
section of the Field List box.
Excel also adds subtotals for each Region and a Grand
Total at the end.
Creating a Pivot Table
Creating a Pivot Table



It would be easier to read the table if the Region field
went across the columns with a total for the three
regions in last column.
No problem!
Change the default layout of the pivot table


Move Region from the Row Labels section of the Field List box
to the Column Labels section
To do this, either:


Drag and drop the Region field from the Row Labels
section to the Column Labels section
Click the Region drop-down and select
Move to Column Labels
Creating a Pivot Table




Formatting the numeric fields
*** Don’t be tempted to format the cells as you would any
other worksheet as a Pivot Table is very fluid ***
Instead you want to ‘tell’ Excel that a particular field
should always have the format $#,##0.
Click on the drop-down in the Sum of Revenue field in
the ∑ Values section of the Field List box and select Value
Field Settings from the menu.
Click the Number Format button
and choose the appropriate format
from the list
Creating a Pivot Table

Voila!
Adding New Fields to the Pivot Table




In the Field List box, check the
Customer field.
Excel adds the field to the Row
Labels.
Try rearranging the fields until you get
a table like you want.
However you arrange the fields, you
will have a lot of blank cells.
Eliminating Blank Cells From a Pivot Table


To override the blank
settings, on the
PivotTable Tools –
Options ribbon, choose
the Options icon in the
PivotTable group.
On the Layout & Format
tab, for the For empty
cells show: setting
change the value to a
zero.
Eliminating Blank Cells From a Pivot Table
Pivot Table Legacy Mode


For those who prefer the Excel 95 – Excel 2003 pivot
table interface which allowed dragging and dropping fields
right onto the pivot table, there is a way.
To go back to that mode:



Create a Pivot Table
On the PivotTable Tools – Options ribbon, choose the Options
icon from the PivotTable group.
In the Pivot Table Options dialog box that appears, go to the
Display tab and choose Classic PivotTable Layout (enables
dragging of fields in the grid).
Microsoft Excel
Relative vs. Absolute Cell References
Relative and Absolute Cell References


Excel’s ability to change cell references in formulas is
called relative referencing.
Using two dollar signs, for example $G$3, indicates an
absolute reference to G3. No matter where you copy the
formula, the reference will always be to cell G3.
Mixed References



i.e., using only one $ sign.
To allow the column to change, place the $ sign after the
cell letter.
To allow the row to change, place the $ sign before the
cell letter.
Microsoft Excel
Logical Functions
IF

Syntax




IF(logical_text, value_if_true, value_if_false)
Uses the comparison operators =, >, <, >=, <=, <>
When reading an IF function, think of the first comma as
the word then, and the second comma as the word
otherwise (or else).
Using ExcelExample2.xlsx, complete the example on the
IF tab.
AND


Used if you need to test for two or more conditions.
Syntax


AND(logical1, logical2,…)
Where logical1, logical2, … are from 1 to 255 expressions
that evaluate to either TRUE or FALSE. The function
returns TRUE only if all arguments are TRUE.
Using ExcelExample2.xlsx, complete the example on the
AND tab.
OR


Used for situations in which a certain formula is based on
meeting one of several conditions.
Syntax


OR(logical1, logical2, …)
Where logical1, logical2, … are from 1 to 255 expressions
that can evaluate to TRUE or FALSE. The function
returns TRUE if any arguments are TRUE.
Using ExcelExample2.xlsx, complete the example on the
OR tab.
Nested IF



The IF function offers only two possible formulas. Either
the logical test is TRUE and the first formula is used or
the logical test is FALSE and the second formula is used.
Many situation have a series of choices, thus we use
nested IF functions.
Using ExcelExample2.xlsx, complete the examples on the
Nested IF tabs.
Nested IF

Hints for employee raise example:
1.
2.
3.
4.
5.
Test for the highest condition first: IF(C2>=4.5, …
Instead of using a value as the third argument, start a second
IF function to be used if the first test is FALSE: IF(C2>=4, …
Start a third IF functions to be used as the value_if_false
argument for the second IF function: IF(C2>=3.5, …
Create the fourth IF function: IF(C2>=2.5, …
With the four IF functions, be careful to provide four closing
parentheses at the end of the function.
Microsoft Excel
Macros
Checking Security Settings

Enabling VBA Security






Select File, Excel Options to open the Excel Settings dialog.
Under the Top options for working with Excel (Popular
button), Click the Show Developer Tab in the Ribbon
checkbox.
Click OK to exit.
On the Developer tab, click Macro Security in the Code group.
The Security dialog appears.
Make sure the Disable All Macros with Notification radio
button is chosen. Excel will alert you whenever you are
opening a workbook that has macros attached.
When you open a document and get the warning that the
document has macros attached, click Enable to enable the
macros.
Recording a Macro


Before starting to record a Macro, think about how to
break the task into easily repeatable steps
Plan out your macro before recording it. Think about the
steps you need to perform.
Recording a Macro
1.
2.
3.
On the Developer ribbon, choose Record Macro.
(Alternatively, click the View tab. On the View ribbon in
the Macros group, click the icon and choose Record
Macro).
In the Record Macro dialog box, type a name for the
macro. The name cannot contain spaces.
Choose if you want to store the macro in the current
workbook, a new workbook, or a special Person Macro
Workbook. For our purposes, choose to store the
macro in the current workbook.
Recording a Macro
4.
5.
6.
7.
8.
9.
10.
Assign a shortcut key for the macro. Ctrl+J ks a safe key,
because nothing is currently assigned to Ctrl+J. This
shortcut will allow you to run the macro again.
Click OK to close the Record Macro dialog.
Turn on the relative recording by clicking the Use Reletive
References icon in the Code group of the Developer ribbon.
Relative recording will record the action of moving a certain
numbers of cells from the active cell.
Perform the actions you want to store in the macro.
Click the red Stop Recording button the left side of the
status bar.
Save the workbook before testing the macro.
Test the macro playback by typing the shortcut key assigned
in Step 4.
Recording a Macro

Steps to take:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Press the Down Arrow key to move to the address cell.
Press Ctrl+X to cut the address
Press the Up Arrow key and then the Right Arrow key to move next to the
name.
Press Ctrl+V to paste the address in cell B1.
Press the Left Arrow Key once and the Down Arrow key twice to move to the
cell for city, state, and zip code.
Press Ctrl+X to cut the city, state, and zip code.
Press the Up Arrow key twice and the Right Arrow key twice to move to cell
C1 (to the right of the street address).
Press Ctrl+V to paste the city, state, and zip code.
Press the Left Arrow key twice and the Down Arrow key once to move to the
now blank row just below the name.
Hold down the Shift key while pressing the Down Arrow key twice in order to
select the three blank rows.
Press Ctrl+- to invoke the delete command. Press R+Enter to delete the row.
Click the red Stop Recording button.
Download