Useful Excel Functions etc

Click here to load reader

  • date post

    26-Dec-2014
  • Category

    Documents

  • view

    126
  • download

    3

Embed Size (px)

Transcript of Useful Excel Functions etc

CONFIDENTIAL

Useful Functions for all Excel Occasions

This document is still in draft and includes the responses to FAQs received from CSS in the ASO and GCO regions for 2006. For any further information please contact: [email protected]

January 17, 2006

This report is solely for the use of client personnel. No part of it may be circulated, quoted, or reproduced for distribution outside the client organization without prior written approval from McKinsey & Company.

Table of ContentsCrucial Functions Match And Index Indirect If Duplicate Entries Testing for duplicate entries Highlighting duplicate entries Tagging duplicate entries Unique Entries Counting unique entries in a Range Extracting unique entries Extracting values common to two lists 5 5 6 7 7 8 9 9 9 10 10 10 11 12

Extracting values on one list and not another 12 Text Returning first word in a String Returning last word in a String 13 13 13

Returning All But First Word In A String 13

Returning any word or words in a String Assigning a letter to a numeric value Range Names

13 14 15

Offset Function basis of Dynamic Range Names 15 Dynamic Range Names for Pivot Tables, data validation, etc 16 Separating Text strings e.g., First and Last Names 17 Address of first minimum in a Range Address of the last minimum in a Range Address of first maximum in a Range Address of the last maximum in a Range Most common String in a Range A Dynamic Range within another Range Numbers Ranking Numbers Summing every Nth value Functions Left Lookups Summing and Counting using multiple criteria Perform two-way table lookups User Defined Functions Example (Easy): Calculate the area of a rectangle 18 18 19 19 19 20 21 21 21 22 22 23 25 26 26

Page 3 of 48

Example (Easy): Calculate Fuel Consumption 29 Examples of UDFs Find the nearest Saturday Remove Spaces Data Validation Validation list Validation formulae Pivot Tables Custom Calculations % of Row % of Total Difference from % Difference from % Of Running Total in 30 33 34 38 38 38 41 41 43 44 44 45 46 47

Page 4 of 48

CRUCIAL FUNCTIONS Match =MATCH(lookup_value,lookup_array,match_type)

Lookup_value

is the value you use to find the value you want in a table.

1. Lookup_value is the value you want to match in lookup_array. For example, when you look up someone's number in a telephone book, you are using the person's name as the lookup value, but the telephone number is the value you want. 2. Lookup_value can be a value (number, text, or logical value) or a cell reference to a number, text, or logical value. Lookup_array is a contiguous range of cells containing possible lookup values. Lookup_array must be an array or an array reference. Match_type is the number -1, 0, or 1. Match_type specifies how Microsoft Excel matches lookup_value with values in lookup_array. 3. If match_type is 1, MATCH finds the largest value that is less than or equal to lookup_value. Lookup_array must be placed in ascending order: ...-2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE. 4. If match_type is 0, MATCH finds the first value that is exactly equal to lookup_value. Lookup_array can be in any order. 5. If match_type is -1, MATCH finds the smallest value that is greater than or equal to lookup_value. Lookup_array must be placed in descending order: TRUE, FALSE, Z-A, ...2, 1, 0, -1, -2, ..., and so on. 6. If match_type is omitted, it is assumed to be 1.

Page 5 of 48

Note: MATCH returns the position of the matched value within lookup_array, not the value itself. For example, MATCH("b",{"a","b","c"},0) returns 2, the relative position of "b" within the array {"a","b","c"}. MATCH does not distinguish between uppercase and lowercase letters when matching text values. If MATCH is unsuccessful in finding a match, it returns the #N/A error value. If match_type is 0 and lookup_value is text, lookup_value can contain the wildcard characters asterisk (*) and question mark (?). An asterisk matches any sequence of characters; a question mark matches any single character. Example

And =AND(logical1,logical2, ...) Logical1, logical2, ... are 1 to 30 conditions you want to test that can be either TRUE or FALSE.

Page 6 of 48

Note: The arguments must evaluate to logical values such as TRUE or FALSE, or the arguments must be arrays or references that contain logical values. If an array or reference argument contains text or empty cells, those values are ignored. If the specified range contains no logical values, AND returns the #VALUE! error value.

Index Returns a value or the reference to a value from within a table or range. There are two forms of the INDEX() function: array and reference. The array form always returns a value or an array of values; the reference form always returns a reference. INDEX(array,row_num,column_num) returns the value of a specified cell or array of cells within array. INDEX(reference,row_num,column_num,area_num) returns a reference to specified cells within reference.

Indirect =indirect(ref_text,a1) Ref_text is a reference to a cell that contains an A1-style reference, an R1C1-style reference, a name defined as a reference, or a reference to a cell as a text string. If ref_text is not a valid cell reference, INDIRECT returns the #REF! error value. 7. If ref_text refers to another workbook (an external reference), the other workbook must be open. If the source workbook is not open, INDIRECT returns the #REF! error value. A1 is a logical value that specifies what type of reference is contained in the cell ref_text.

Page 7 of 48

8. If a1 is TRUE or omitted, ref_text is interpreted as an A1-style reference. 9. If a1 is FALSE, ref_text is interpreted as an R1C1-style reference.

If =(logical_test,value_if_true,value_if_false) The IF statement returns one value if a condition you specify evaluates to TRUE and another value if it evaluates to FALSE. Use IF to conduct conditional tests on values and formulas.

Logical_test is any value or expression that can be evaluated to TRUE or FALSE. For example, A10=100; if the value in cell A10 is equal to 100, the expression evaluates to TRUE. Otherwise, the expression evaluates to FALSE. Value_if_true is the value that is returned if logical_test is TRUE. For example, if this argument is the text string "Within budget" and the logical_test argument evaluates to TRUE, then the IF function displays the text "Within budget". If logical_test is TRUE and value_if_true is blank, this argument returns zero. Value_if_true can be another formula. Value_if_false is the value that is returned if logical_test is FALSE. Value_if_false can be another formula.

Note: Up to seven IF functions can be nested as value_if_true and value_if_false arguments to construct more elaborate tests. See the last of the following examples. When the value_if_true and value_if_false arguments are evaluated, IF returns the value returned by those statements. If any of the arguments to IF are arrays, every element of the array is evaluated when the IF statement is carried out.

Page 8 of 48

DUPLICATE ENTRIES Testing for duplicate entries If you need to determine whether a list in Excel has duplicate entries, use the following formula. It will display "Duplicates" if the list in Range1 has duplicate entries, or "No Duplicates" if the range does not have any duplicates.

=IF(MAX(COUNTIF(Range1,Range1))>1,"Duplicates","No Duplicates")

This is an array formula, so press Ctrl+Shift+Enter rather than just Enter when you first enter the formula, and whenever you edit it. This formula requires that the complete range contain data. If only the first N cells contain data, and the rest are empty, the formula will return "Duplicates" because it considers the empty cells to be duplicates of themselves. If you want the formula to look only that the cells that contains data, use a formula like the following:

=IF(MAX(COUNTIF(INDIRECT("A2:A"&(MAX((A2:A500"")*ROW(A2:A50 0)))),INDIRECT("A2:A"&(MAX((A2:A500"")*ROW(A2:A500))))))>1,"Duplic ates","No Duplicates")

This formula will look only that the cells from A2 down to the last cell that contains data. This is an array formula, so press Ctrl+Shift+Enter.

Highlighting duplicate entries Use Excel's Conditional Formatting tool to accomplish this. Highlight the entire Range1. Select Format>Conditional Formatting. Change the "Cell Value Is" option to "Formula Is" and enter the following formula in the formula text box:

Page 9 of 48

=IF(COUNTIF(Range1, A5)>1,TRUE,FALSE)

Where A5 is the first cell in Range1. Then, click the Format button and select the font or color you want your cell formatted with. Click OK. Duplicate entries in Range1 will be formatted as you selected.

Tagging duplicate entries Instead of highlighting duplicates, you may want to "tag" them by placing the word "Duplicate" next to each duplicate entry in the range. In an empty column next to Range1, enter the following formula, and autofill the column with the formula:

=IF(COUNTIF(Range1,XXX)>1,"Duplicate","")

Change XXX to the first cell of Range1. If a cell is duplicated in Range1, the word "Duplicate" will appear next to each cell.

UNIQUE ENTRIES Counting unique entries in a Range To count the number of unique entries in the list, use the following array formula:

=SUM(IF(FREQUENCY(IF(LEN(Range1)>0,MATCH(Range1,Range1,0),""), IF(LEN(Range1)>0,MATCH(Range1,Range1,0),""))>0,1))

This will return the number of unique entries in Range1. It will not count blanks at all.

Page 10 of 48

If your data does not have any blanks in the range, use the following Array Formula: =SUM(1/COUNTIF(A1:A10,A1:A10))

If your data has only numer