Excel 201 Macros & Controls
Excel 201 Macros & Controls
Advanced Skills
This presentation is solely for the use of ZS Associates personnel. No part of it may be circulated, quoted or reproduced for distribution outside of ZS Associates without prior written approval of ZS Associates.
Required Materials
Please ensure you have the Excel 201 training materials on your computer
Training materials for this session may have already been loaded on your laptops If not, download all files from:
[ENTER PATH HERE]
For all exercises, refer to Excel 201 Exercises v1.0.xls Solutions can be found in Excel 201 - Solution v1.0.xls
2009 ZS Associates
Introduction
Agenda
Introduction Concepts to Improve Workbook Usability Advanced Functions and Formulae Advanced Defined Names 5 min 45 min 45 min 30 min
Controls
Array Formulae
30 min
30 min
2009 ZS Associates
Introduction
2009 ZS Associates
Introduction
Agenda
Introduction Concepts to Improve Workbook Usability Advanced Functions and Formulae Advanced Defined Names 5 min 45 min 45 min 30 min
Controls
Array Formulae
30 min
30 min
2009 ZS Associates
Workbook Concepts
Conditional Formats change the appearance of a cell to reflect the value it contains
When dealing with large amounts of data, it can be helpful to highlight records that meet certain criteria
Cell formats can be specified using your customized toolbars or the cell properties menu Can be used to highlight values that meet certain criteria (e.g. outliers)
2009 ZS Associates
Workbook Concepts
Advanced uses of conditional formats allow for multiple formats and multiple conditions A formula can be used instead of the cell value to take advantage of relative references or worksheet functions
If the formula evaluates to TRUE, the formatting will be applied
2009 ZS Associates
Workbook Concepts
Data Validation restricts the possible values of a cell to a given list or range
The list option of Data Validation can be used as a simple version of a drop down box.
Customized Alerts
Workbook Concepts
To lock a worksheet intended for client use: Step 1: Unlock cells that users should be able to edit Step 2: Lock the worksheet
Passwords can be required to unlock the worksheet Worksheet passwords are not secure!
2009 ZS Associates
Workbook Concepts
Workbook protection can be used to limit access to the workbook or changes to its structure
Workbook protection can be used to require a password to open a workbook or save changes to a workbook
Other workbook protection options can be found in Tools > Protection ([Alt]+T, P)
2009 ZS Associates
10
Workbook Concepts
ZS has been hired by ABC Pharma to set product sales goals for each geography in their sales force
ABC Pharma has a single product with access to accurate and reliable account level product and market sales data They would like to use a goal based plan for their sales forces IC plan
In a goal based plan, the field gets a bonus proportional to their goal attainment Attainment is calculated by dividing sales by the goal
Situation
Complication
ABC pharmas product is very mature and they would like their goals to be based 90% on the previous years product sales and 10% on each geographys untapped potential
How can we best design and create an excel workbook to calculate their goals?
Question
2009 ZS Associates
11
Workbook Concepts
After completing these exercises, you will understand the inputs to ABC Pharmas goal setting process Review the inputs on the Inputs worksheet and review the raw account level sales data on the Raw Account Sales Data worksheet Complete the tasks 1 5 listed on the Exercises worksheet
After completing the exercises in this section, you should understand data validation, formula auditing, named ranges and conditional formatting
2009 ZS Associates
12
Agenda
Introduction Concepts to Improve Workbook Usability Advanced Functions and Formulae Advanced Defined Names 5 min 45 min 45 min 30 min
Controls
Array Formulae
30 min
30 min
2009 ZS Associates
13
We will discuss a few advanced features that provide functionality beyond what was covered in Excel 101
Function
VLOOKUP HLOOKUP MATCH INDEX OFFSET INDIRECT ADDRESS ROW COLUMN
Syntax
VLOOKUP(Lookup value, Lookup table, Offset, Type) HLOOKUP(Lookup value, Lookup table, Offset, Type) MATCH (Lookup value, Lookup range, Type) INDEX (Index range, Row, Column) OFFSET (Reference, Rows, Columns, Height, Width) INDIRECT(Reference) ADDRESS(Row_num, Col_num) ROW(Reference) COLUMN(Reference)
Comments
Searches for a value in the leftmost column of a table, and then returns a value in the same row from the column specified Searches for a value in the topmost row of a table, and then returns a value in the same column from the row specified Returns the relative position of an item in an array that matches a specified value in a specified order Returns a value or the reference to a value from within a table or range Returns a range of specified Height and Width, which is located a specific number of Rows and Columns from the stated reference Returns the value in the cell which is specified by the stated reference Returns the address of the cells whose row and column numbers are used as parameters Returns the row number of a reference Returns the column number of a reference
SUMIF
COUNTIF RANK SUMPRODUCT TRANSPOSE FREQUENCY TABLE
2009 ZS Associates
SUMIF() and COUNTIF() functions can be used to aggregate data to a desired level
Aggregate functions helps allow the same dataset to be used for different analyses These functions are preferred over Pivot tables as they eliminate the refresh task
2009 ZS Associates
15
Use the rank function to determine a values size relative to others in a list
A 1 2 3 4 5 6 7 Territory A B C D Sales ($MM) 2.1 1.7 3.0 1.8 B C D E
Sales Rank 2 4 1 3
After using the rank function, use other functions such as index and match to quickly produce tables for a given attribute listing the top or bottom items in a list
A 11 12 13 14 15 16 17
2009 ZS Associates
B Sales Rank 1 2 3 4
Territory C A D B
The OFFSET function is used to return a value or range of values based on location inputs
OFFSET (Reference, Rows, Columns, Height, Width) Returns a range of specified Height and Width, which is located a specific number of Rows and Columns from the stated reference
If the Reference is a range of cells, the offset is counted from the upper left corner of the Reference range.
2009 ZS Associates
17
TRANSPOSE() is different from pasting values; like any other function, it dynamically updates values when the underlying data changes
2009 ZS Associates
18
2009 ZS Associates
19
One and two-variable data tables can be used to easily perform sensitivity analysis on a complicated model
A 1 2 3 4 5 6 7 B mROI Forecast ($MM) Cost / PDE C 25% 550 110 D E F G H I J K L M
select the entire table (C12:G17) On the Data menu, click Table In the Row input cell box, enter the reference to the input cell for the input values in the row (C4) In the Column input cell box, enter the reference to the input cell for the input values in the column (C2) Click OK
A B D E F G H Optimal Size Forecast ($MM) =L4 525 550 575 600 0% 25% 50% {=Table(C4,C2)} 75% 100% C A B
10 11 12 13 14 15 16 17 18
D E F G H Optimal Size Forecast ($MM) 525 550 575 600 147 154 162 171 138 144 151 159 129 134 140 147 120 124 129 135 111 114 118 123
Note: this formula is not an array formula (even though it will appear with brackets). It must be entered using the data table prompt 20
mROI
mROI
We will also discuss how IS functions can be used to check results, and improve the appearance of workbooks IS functions check the type of the parameters and return TRUE or FALSE The IS functions are useful in formulae for testing the outcome of a calculation
Function
ISBLANK ISERR ISERROR ISLOGICAL ISNA ISNONTEXT ISNUMBER ISREF ISTEXT
Syntax *
ISBLANK(value) ISERR(value) ISERROR(value) ISLOGICAL(value) ISNA(value) ISNONTEXT(value) ISNUMBER(value) ISREF(value) ISTEXT(value) An empty cell. Any error value except #N/A.
Tests for
Any error value (#N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or #NULL!). A logical value. The #N/A (value not available) error value. Any item that is not text. (Note that this function returns TRUE if value refers to a blank cell.) A number. A reference. Text.
21
2009 ZS Associates
22
After completing the exercises in this section, you will have successfully set the goals for each of ABC Pharmas territories
2009 ZS Associates
23
Agenda
Introduction Concepts to Improve Workbook Usability Advanced Functions and Formulae Advanced Defined Names 5 min 45 min 45 min 30 min
Controls
Array Formulae
30 min
30 min
2009 ZS Associates
24
2009 ZS Associates
25
2009 ZS Associates
26
Worksheet Name
! (Separator)
Range Name
ADDRESS() will help identify the location name used by Excel INDIRECT() will help you use names that have been defined ROW() / COLUMN() return the number of a row or column
27
2009 ZS Associates
2nd Column
1st Row
= ADDRESS(1,2)
28
2009 ZS Associates
Example:
Named Range MDs Named Range Details
= SUM(INDIRECT(C1))
= SUM(INDIRECT(B1))
2009 ZS Associates
29
While it is important to be aware of this functionality in case you encounter it, we recommend that you do NOT use it; it makes workbooks very difficult to understand
2009 ZS Associates
30
= MySum
We can define a named range called MySum that sums the range given in Refers to:
The same function can be used to calculate the total number details.
While it is important to be aware of this functionality in case you encounter it, we recommend that you do NOT use it; it makes workbooks very difficult to understand
2009 ZS Associates
31
Lets make our workbook more dynamic by replacing some of the static named ranges with dynamic ones Complete exercise 14 listed on the Exercises worksheet of the goal setting workbook Delete the named ranges on the worksheet Raw Account sales Data Replace them with dynamically defined named ranges
Use the offset and counta functions in the named range definition
In future goal setting cycles, if the number of accounts changes, the goal setting workbook will now calculated territory level sales correctly!
2009 ZS Associates
32
Controls
Agenda
Introduction Concepts to Improve Workbook Usability Advanced Functions and Formulae Advanced Defined Names 5 min 45 min 45 min 30 min
Controls
Array Formulae
30 min
30 min
2009 ZS Associates
33
Controls
ActiveX controls provide many more options than Forms. But, sufficient care must be taken as ActiveX controls are sometimes unstable.
2009 ZS Associates
34
Controls
List Box
Option Button
Group Boxes
Check Box
Button
Spinner
Scroll Bar
2009 ZS Associates
35
Controls
2. Based on the users selection, the control outputs a result to the cell link
The cell link is designated under the Control tab in the Format Control dialog box
named ranges
2009 ZS Associates
36
Controls
The Drop Down/Combo Box and List Box allow the user to select from a pre-defined list
Functionality: Drop Down/Combo and List Boxes The item selected is highlighted and displayed in the text box The control returns a value representing the position of the selected Drop Down Box List Box item
When to use which ? Drop Down/Combo Boxes requires less space on the worksheet The List Box provides faster access Control Properties INPUT RANGE CELL LINK DROP DOWN LINES SELECTION TYPE
2009 ZS Associates
37
Controls
Option Buttons and Check Boxes are used to select multiple or a single option within a group
Functionality
Both allow for a choice to be turned off/on Return a value related to the choice selected Group Boxes Option Button Single Selection: Selecting one button will deselect any others The # of the button checked Tell Excel which buttons work together Format options for the user Check Box Mutliple Selections: Boxes are independent Value for each box Format options for the user
Check Box
2009 ZS Associates
38
Controls
Scroll Bars and Spinners are linked to a cell or a text box to manipulate the values inside
Functionality: Scroll Bar and Spinner Adjust the value of a cell (cell link) from a range of integer values Spinner Scroll Bar
20
Control Properties CURRENT VALUE MINIMUM VALUE MAXIMUM VALUE INCREMENTAL CHANGE PAGE CHANGE CELL LINK
2009 ZS Associates
39
Controls
Buttons, Labels, Text Boxes, and AutoShapes can initiate the execution of VBA code and can display cell contents
Button Label Text Box AutoShape
Show Graph
Functionality An advantage of displaying data in a control versus a cell is the ability to freeze the size, position and format of the control regardless of what happens on the rest of the worksheet. They do not pass a value back to a cell They do not have a Control tab on the Format Control dialog box.
2009 ZS Associates
40
Controls
2009 ZS Associates
41
Controls
Improve the user interface of a workbook by replacing some of the inputs cells with forms and/or controls Complete exercise 15 listed on the Exercises worksheet of the goal setting workbook Replace the input cells for maximum achievable share and the % of goal based on history with horizontal scroll bar forms Set appropriate minimum, maximum, and increment values for the scroll bars
Forms and controls can make it easy for users to refine workbook inputs
2009 ZS Associates
42
Array Formulae
Agenda
Introduction Concepts to Improve Workbook Usability Advanced Functions and Formulae Advanced Defined Names 5 min 45 min 45 min 30 min
Controls
Array Formulae
30 min
30 min
2009 ZS Associates
43
Array formulae are a powerful feature of Excel that can be used to summarize lists of data by operating on each cell in an array
2009 ZS Associates
44
Array formulae are very powerful formulae that also provide flexibility in designing Excel tools
The offset worksheet function is used with array formulae to show territories in the selected region
The values get updated automatically when data is refreshed convenient when data refresh happens often There is only one table to deal with easy to expand to accommodate additional columns
2009 ZS Associates
45
When using multi-cell array formulae, all single-cell references are treated as absolutes In the example below, a multi-cell array formula is entered while selecting cells A2 to B2. The same value will result in all cells, because the reference to A1 is treated as an absolute
A 1 2 3 4 5 10 20 20 B 25 20 35 C 82 20 92
= { A1 + 10 } = { A1:C1 + 10 }
2009 ZS Associates
46
We can use the binary logic shortcuts instead of writing out the IF() function
Comparison operators like < , > result in a TRUE or FALSE (Boolean) reply
A 5 B 10 = (A>B) FALSE = (A<B) TRUE = (A=B) FALSE
To convert Boolean (True/False) values to Binary (1/0) values that can be used in other calculations, multiply the result by 1 True * 1 = 1 False * 1 = 0
A 5 B 10 = (A>B)*1 = (A<B)*1 = (A=B)*1 0 1 0
2009 ZS Associates
47
Using binary logic with array formulae allows you to create advanced formulae with multiple criteria The AND operator can be simulated with multiplication ( * )
X 0 0 1 1 AND Y 0 1 0 1 X AND Y FALSE FALSE FALSE TRUE
X 0 0 1 1
AND Y 0 1 0 1
X*Y 0 0 0 1
Note: There is no direct arithmetic operator that is equivalent to the NOT operator
2009 ZS Associates
48
2009 ZS Associates
49
ZS will also set district and regional goals and provide several territory goal summaries for ABC Pharma Complete exercises 16 - 24 listed on the Exercises worksheet of the goal setting workbook Calculate district and region historical product and market sales Use advanced conditional formatting to highlight territories with the highest goals or growth Use the frequency function to create a histogram Use index, match, and indirect to fill in values inside summary tables
Using advanced functions and formulae gives your workbooks tremendous power and flexibility!
2009 ZS Associates
50
Appendix
Appendix A
Keyboard Shortcuts
Appendix
Keyboard shortcuts
F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Alone Help Formula Bar Paste Refer/Repeat Goto Next Pane Check Spelling Extend Toggle Calculate Menu Bar New Chart Save As Shift+ Context Help Edit a Cell Note Function Wizard Find Next Find Previous Pane Add Mode Toggle Calculate Sheet Shortcut Menu New Worksheet Save Ctrl+ Show Info Window Define Name Close Restore Next Window Move Size Minimize Workbook Maximize Workbook Excel 4 Macro Sheet Open Ctrl+Shift+ Alt+ F11 F12 Exit
2009 ZS Associates
52
Appendix
New Open Print Save Close Next Sheet in Workbook Prev Sheet in Workbook
Show/Hide Std Toolbar Show/Hide Outline Symbols Hide Selected Rows Hide Selected Columns Display Selected Rows Display Selected Columns Display formulas/values
Format Cells Bold Italic Underline Strike through Style Box Add Outline Border Remove All Borders
2009 ZS Associates
53
Appendix
Appendix B
Adding drop-down menus to charts
Appendix
Adding Drop Down/Combo and List Boxes can be time intensive, but creates a dramatic effect Graphs with Drop Downs ease the presentation of multiple graphs: Present different scenarios in an easily accessible, uncluttered worksheet User can focus on what he/she wants Eliminates time necessary to scroll through multiple graphs When used effectively, creates a more appealing user interface Refer to an entire data range
2009 ZS Associates
55
Appendix
To add Drop Down boxes to your graphs, prepare the underlying data first
Prepare the raw data table Create a table with columns for each of the pull-down boxes and the x- and y-axis values
Add a unique key by concatenating the pulldown box columns with the x-axis values
Unique Key A _1_1_0 A _1_1_1 A _1_1_2 A _1_1_3 A _1_1_4 A _1_1_5 Product Ventile Time Period A 1 1 A 1 1 A 1 1 A 1 1 A 1 1 A 1 1 P1E 0 1 2 3 4 5 Market Share # Doctors 8.61% 291 13.20% 352 17.46% 176 18.15% 122 15.36% 62 26.19% 41
Xaxis values
Yaxis values
Prepare a final table to show the data for the graph well use INDEX/MATCH functions to fill in the table dependant on the users selections
2009 ZS Associates
56
Appendix
Create the graph based on this final data table Changing the drop down boxes will update the data table and your graphs
P1E 0 1 2 3 4 5 Market Share 8.61% 13.20% 17.46% 18.15% 15.36% 26.19% # doctors 291 352 176 122 62 41 Product 1 A Cell designated as "Cell Link" Cell referenced to variable chosen with pull-down box
Xaxis values
2009 ZS Associates
Yaxis values
57
Appendix
Appendix C
Using dynamic ranges with graphs
Appendix
Graphs and charts can use Dynamic Ranges to ensure the correct scale is used to present data
Dynamic named ranges can be used to limit the cells in a named range only to nonempty cells Useful as inputs to graphs Ensures that the data range consists of only nonempty cells Changes the scale of the graph to exactly fit the data points
2009 ZS Associates
59
Appendix
Rather than entering cell references, enter Workbookname.xls!Rangename When the named range changes size, the data on which the graph is based also changes size.
2009 ZS Associates
60
Appendix
Appendix D
Formula Auditing
Appendix
Highlight a section of a formula in the formula bar and hit F9 to see that portion of the formula evaluated
2009 ZS Associates
62
Appendix
Appendix E
Background Information for Exercise
Workbook Concepts
Goal setting review how we will set goals for ABC Pharma
Analysis Approach
1
The sum of every territory goal should equal the national forecast Goal1 + Goal2 + Goal3 + + Goaln = ABCs national forecast Goal1(historical component) + Goal2(historical component) + Goal3(historical component) + + Goaln(historical component) = 90% * national forecast For example, if in the previous year territory 1 accounted for 3.2% of national sales, then: Goal1(historical component) = 90% * national forecast * 3.2%
2
90% of the national forecast will be allocated to every territory as the history portion of their goal based on each territorys proportion of the nations previous year product sales
3
10% of the national forecast will be allocated to every territory as the untapped potential (U.P.) portion of their goal based on each territorys proportion of the nations untapped potential Untapped potential in a given territory is found by subtracting the current product sales from the maximum achievable sales (M.A.S.) The maximum achievable sales (M.A.S.) are the market sales multiplied by the maximum achievable share
2009 ZS Associates
Goal1(U.P. component) + Goal2(U.P. component) + Goal3(U.P. component) + + Goaln(U.P. component) = 10% * national forecast U.P. = M.A.S. Current Product Sales For example, if in the previous year territory 1 had $1.2 MM in sales and has M.A.S. of $1.5 MM, then territory 1s untapped potential is $300K For example, market sales in territory 1 are $3.0 MM and the maximum acheivable share is 50%, so the maximum achievable sales are: $3.0 MM * 50% = $1.5 MM
64
20090416 - Excel 201 -v1.0