You are on page 1of 306

Excel -- Filters -- Advanced Filters -Introduction

1. Advanced Filters--Introduction a) Apply an Advanced Filter b) Filter Unique Records c) Extract Data to Another Worksheet d) Setting up the Criteria Range e) Using Wildcards in Criteria f) Criteria Examples 2. Advanced Filters -- Complex Criteria Apply an Advanced Filter 1. Set up the database 1. The first row (A1:D1) has headings. 2. Subsequent rows contain data. 3. There are no blank rows within the database. 4. There is a blank row at the end of the database, and a blank column at the right. 2. Set up the Criteria Range (optional) In the criteria range, you can set the rules for the data that should remain visible after the filter is applied. You can use one criterion, or several. 1. In this example, cells F1:F2 are the criteria range. 2. The heading in F1 exactly matches a heading (D1) in the database. 3. Cell F2 contains the criterion. The > (greater than) operator is used, with the number 500 (no $ sign is included).. After the filter is applied, orders with a total greater than $500 will remain visible. Other operators include: < less than <= less than or equal to >= greater than or equal to <> not equal to
For a zipped workbook with sample data and criteria, click here.

3. Set up the Extract Range (optional) If you plan to copy the data to another location, you can specify the columns that you want to extract. If you want to extract ALL columns, you can leave the extract range empty. 1. Select the cell at the top left of the range for the extracted data. 2. Type the headings for the columns that you want to extract. These must be an exact match for the column headings, in spelling and punctuation. The column order can be different, and any or all of columns can be included. 4. Apply the Filter 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter. (In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. You can choose to filter the list in place, or copy the results to another location. 4. Excel should automatically detect the list range. If not, you can select the cells on the worksheet. 5. Select the criteria range on the worksheet 6. If you are copying to a new location, select a starting cell for the copy Note: If you copy to another location, all cells below the extract range will be cleared when the Advanced Filter is applied. 7. Click OK

Filter Unique Records You can use an Advanced Filter to extract a list of unique items in the database. For example, get a list of customers from an order list, or compile a list of products sold: Note: The list must contain a heading, or the first item may be duplicated in the results. 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. Choose 'Copy to another location'. 4. For the List range, select the column(s) from which you want to extract the unique values. 5. Leave the Criteria Range blank. 6. Select a starting cell for the Copy to location. 7. Add a check mark to the Unique records only box.

8. Click OK. Watch the Video View the steps described above, in a short video clip. Excel 2007 video

Extract Data to Another Worksheet If the database is on Sheet1 and you would like to extract data to Sheet2: 1. Go to Sheet 2 2. Select a cell in an unused part of the sheet (cell C4 in this example). 3. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 4. Choose Copy to another location. 5. Click in the List Range box 6. Select Sheet 1, and select the database. 7. (optional) Click in the Criteria range box. 8. Select the criteria range 9. Click in the Copy to box. 10. Select the cell on Sheet 2 in which you want the results to start, or select the headings that you have typed on Sheet 2. 11. (optional) Check the box for Unique Values Only 12. Click OK Setting up the Criteria Range AND vs OR If a record meets all criteria on one row in the criteria area, it will pass through the filter. In example 1, at right -customer must be MegaMart AND product must be Cookies 1. AND total must be greater than 500. Criteria on different rows are joined with an OR operator. In the second example at right -customer must be MegaMart OR product must be Cookies OR total must be greater than 500. 2. By using multiple rows, you can combine the AND and OR operators. In the third example at right -customer must be MegaMart AND product must be Cookies OR product must be Cookies AND total must be greater than 500. 3.

Using Wildcards in Criteria Use wildcard characters to filter for a text string in a cell. The * wildcard The asterisk (*) wildcard character represents any number of characters in that position, including zero characters. In this example, any customer whose name contains "mart" will pass through the filter. The ? wildcard The question mark (?) wildcard character represents one characters in that position. In this example any 4-letter product that begins with c, and ends with ke, will pass through the filter. The ~ wildcard The tilde (~) wildcard character lets you search for characters that are used as wildcards. In this example any products that begins with Good and ends with Eats, will pass through the filter. To find only the product named Good*Eats, use a tilde character in front of the asterisk.

Criteria Examples
Extract Items in a Range

To extract a list of items in a range, you can use two columns for one of the fields (e.g. Date). If you enter two criteria on the same row in the criteria range, you create an AND statement. In this example, any records that are extracted must be greater than the first date AND less than the second date.

Create Two or More Sets of Conditions

If you enter criteria on different rows in the criteria range, you create an OR statement. In this example, extracted records must meet both conditions in row 2 OR both conditions in row 3.

Extract Items with Specific Text

When you use text as criteria with an advanced filter, Excel finds all items that begin with that text. For example, if you type "Ice" as a criterion, Excel finds "Ice", "Ice Cream" and "Ice Milk" To extract only the records for Ice, use the following format: ="=Ice"

Excel -- Filters -- Advanced Filter -- Complex Criteria


Set up the Database Extract the Top Five Records Filter for Matching Data in Two Columns Filter for Unmatched Data in Two Columns Find Numbers within a Number Filter Rows with Blank Cells Filter Items in a List This page gives details on criteria used for specialized Advanced Filters. For an introduction to Advanced Filters, click here. Set up the Database The samples on this page assume a data layout as shown at right. The database is in columns A:D and the criteria range starts in cell F1. Note: When you use a formula as the criterion, leave the heading cell blank, or use a heading that does not match any of the table headings. For a zipped workbook with sample data and criteria, click

here.

Extract the Top Five Records F1: Criteria Heading -- Leave blank F2: Criteria: =D2>=LARGE($D$2:$D$28,5) The LARGE function returns the fifth largest value in the range D2:D28. An absolute reference is used for the range -$D$2:$D$28. Cell D2, the first cell with data in the Total column, is compared to this value. A relative reference is used for this -- D2. Rows with a Total value that is greater than or equal to the fifth largest number, pass through the filter. (Note: In the case of ties, more than five records may be returned) Filter for Matching Data in Two Columns F1: Criteria Heading -- Leave blank F2: Criteria: =C2=D2 In each record, the Order date is compared to the Ship date. A relative reference is used for this -C2 and D2. Rows where the dates are equal pass through the filter. Filter for Unmatched Data in Two Columns F1: Criteria Heading -- Leave blank F2: Criteria: =C2<>D2 In each record, the Invoice amount is compared to the amount Paid. A relative reference is used for this -- C2 and D2. Rows where the amounts are not equal are displayed. Note: You can use a column heading in the criteria formula, instead of a cell reference. The formula will return the #NAME? or #VALUE! error, but the filter will work correctly. For example:

F2: Criteria: =Invoice<>Paid

Find Numbers within a Number F1: Criteria Heading -- Leave blank F2: Criteria: =ISNUMBER(FIND("8",C2)) The FIND function looks for the string "8" in the contents of cell C2. If it finds the number, the result is the location of the number in the string. If the number is not found, an Error is the result. Filter Rows with Blank Cells F1: Criteria Heading -- Leave blank F2: Criteria: =C2="" In each record, the value in column C is checked. If it is an empty string, the record passes through the filter. Filter Items in a List Column H: Enter the list of items that you want to match F1: Criteria Heading -Leave blank F2: Criteria: =COUNTIF(H:H,C2) In each record, the value in column C is checked. If it is in the list in column H, the record passes through the filter. For a zipped workbook with sample data and criteria, click here. 1. Introduction to Advanced Filters

Apply an Advanced Filter 1. Set up the database 1. The first row (A1:D1) has headings. 2. Subsequent rows contain data. 3. There are no blank rows within the database. 4. There is a blank row at the end of the database, and a blank column at the right. 2. Set up the Criteria Range (optional)

For a zipped workbook with sample data and criteria, click here.

In the criteria range, you can set the rules for the data that should remain visible after the filter is applied. You can use one criterion, or several. 1. In this example, cells F1:F2 are the criteria range. 2. The heading in F1 exactly matches a heading (D1) in the database. 3. Cell F2 contains the criterion. The > (greater than) operator is used, with the number 500 (no $ sign is included).. After the filter is applied, orders with a total greater than $500 will remain visible. Other operators include: < less than <= less than or equal to >= greater than or equal to <> not equal to

3. Set up the Extract Range (optional) If you plan to copy the data to another location, you can specify the columns that you want to extract. If you want to extract ALL columns, you can leave the extract range empty. 1. Select the cell at the top left of the range for the extracted data. 2. Type the headings for the columns that you want to extract. These must be an exact match for the column headings, in spelling and punctuation. The column order can be different, and any or all of columns can be included.

4. Apply the Filter 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter. (In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. You can choose to filter the list in place, or copy the results to another location. 4. Excel should automatically detect the list range. If not, you can select the cells on the worksheet. 5. Select the criteria range on the worksheet 6. If you are copying to a new location, select a starting cell for the copy Note: If you copy to another location, all cells below the extract range will be cleared when the Advanced Filter is applied. 7. Click OK

Filter Unique Records You can use an Advanced Filter to extract a list of unique items in the database. For example, get a list of customers from an order list, or compile a list of products sold: Note: The list must contain a heading, or the first item may be duplicated in the results. 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. Choose 'Copy to another location'. 4. For the List range, select the column(s) from which you want to extract the unique values. 5. Leave the Criteria Range blank. 6. Select a starting cell for the Copy to location. 7. Add a check mark to the Unique records only box. 8. Click OK. Watch the Video View the steps described above, in a short video clip. Excel 2007 video

Extract Data to Another Worksheet If the database is on Sheet1 and you would like to extract data to Sheet2: 1. Go to Sheet 2 2. Select a cell in an unused part of the sheet (cell C4 in this example). 3. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 4. Choose Copy to another location. 5. Click in the List Range box 6. Select Sheet 1, and select the database. 7. (optional) Click in the Criteria range box. 8. Select the criteria range 9. Click in the Copy to box. 10. Select the cell on Sheet 2 in which you want the results to start, or select the headings that you have typed on Sheet 2. 11. (optional) Check the box for Unique Values Only 12. Click OK Setting up the Criteria Range AND vs OR If a record meets all criteria on one row in the criteria area, it will pass through the filter. In example 1, at right -customer must be MegaMart AND product must be Cookies 1. AND total must be greater than 500. Criteria on different rows are joined with an OR operator. In the second example at right -customer must be MegaMart OR product must be Cookies OR total must be greater than 500. 2. By using multiple rows, you can combine the AND and OR operators. In the third example at right -customer must be MegaMart AND product must be Cookies OR product must be Cookies AND total must be greater than 500. 3. Using Wildcards in Criteria Use wildcard characters to filter for a text string in a cell.

The * wildcard The asterisk (*) wildcard character represents any number of characters in that position, including zero characters. In this example, any customer whose name contains "mart" will pass through the filter. The ? wildcard The question mark (?) wildcard character represents one characters in that position. In this example any 4-letter product that begins with c, and ends with ke, will pass through the filter. The ~ wildcard The tilde (~) wildcard character lets you search for characters that are used as wildcards. In this example any products that begins with Good and ends with Eats, will pass through the filter. To find only the product named Good*Eats, use a tilde character in front of the asterisk.

Criteria Examples
Extract Items in a Range

To extract a list of items in a range, you can use two columns for one of the fields (e.g. Date). If you enter two criteria on the same row in the criteria range, you create an AND statement. In this example, any records that are extracted must be greater than the first date AND less than the second date.
Create Two or More Sets of Conditions

If you enter criteria on different rows in the criteria range, you create an OR statement. In this example, extracted records must meet both conditions in row 2 OR both conditions in row 3.

Extract Items with Specific Text

When you use text as criteria with an advanced filter, Excel finds all items that begin with that text. For example, if you type "Ice" as a criterion, Excel finds "Ice", "Ice Cream" and "Ice Milk" To extract only the records for Ice, use the following format: ="=Ice" 2. Advanced Filters -- Complex Criteria For a zipped workbook with sample data and criteria, click here.

Apply an Advanced Filter 1. Set up the database 1. The first row (A1:D1) has headings. 2. Subsequent rows contain data. 3. There are no blank rows within the database. 4. There is a blank row at the end of the database, and a blank column at the right. 2. Set up the Criteria Range (optional)

For a zipped workbook with sample data and criteria, click here.

In the criteria range, you can set the rules for the data that should remain visible after the filter is applied. You can use one criterion, or several. 1. In this example, cells F1:F2 are the criteria range. 2. The heading in F1 exactly matches a heading (D1) in the database. 3. Cell F2 contains the criterion. The > (greater than) operator is used, with the number 500 (no $ sign is included).. After the filter is applied, orders with a total greater than $500 will remain visible. Other operators include: < less than <= less than or equal to >= greater than or equal to <> not equal to

3. Set up the Extract Range (optional) If you plan to copy the data to another location, you can specify the columns that you want to extract. If you want to extract ALL columns, you can leave the extract range empty. 1. Select the cell at the top left of the range for the extracted data. 2. Type the headings for the columns that you want to extract. These must be an exact match for the column headings, in spelling and punctuation. The column order can be different, and any or all of columns can be included. 4. Apply the Filter 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter. (In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. You can choose to filter the list in place, or copy the results to another location. 4. Excel should automatically detect the list range. If not, you can select the cells on the worksheet. 5. Select the criteria range on the worksheet 6. If you are copying to a new location, select a starting cell for the copy Note: If you copy to another location, all cells below the extract range will be cleared when the Advanced Filter is applied. 7. Click OK

Filter Unique Records You can use an Advanced Filter to extract a list of unique items in the database. For example, get a list of customers from an order list, or compile a list of products sold: Note: The list must contain a heading, or the first item may be duplicated in the results. 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. Choose 'Copy to another location'. 4. For the List range, select the column(s) from which you want to extract the unique values. 5. Leave the Criteria Range blank. 6. Select a starting cell for the Copy to location. 7. Add a check mark to the Unique records only box.

8. Click OK. Watch the Video View the steps described above, in a short video clip. Excel 2007 video

Extract Data to Another Worksheet If the database is on Sheet1 and you would like to extract data to Sheet2: 1. Go to Sheet 2 2. Select a cell in an unused part of the sheet (cell C4 in this example). 3. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 4. Choose Copy to another location. 5. Click in the List Range box 6. Select Sheet 1, and select the database. 7. (optional) Click in the Criteria range box. 8. Select the criteria range 9. Click in the Copy to box. 10. Select the cell on Sheet 2 in which you want the results to start, or select the headings that you have typed on Sheet 2. 11. (optional) Check the box for Unique Values Only 12. Click OK Setting up the Criteria Range AND vs OR If a record meets all criteria on one row in the criteria area, it will pass through the filter. In example 1, at right -customer must be MegaMart AND product must be Cookies 1. AND total must be greater than 500. Criteria on different rows are joined with an OR operator. In the second example at right -customer must be MegaMart OR product must be Cookies OR total must be greater than 500. 2. By using multiple rows, you can combine the AND and OR operators. In the third example at right -customer must be MegaMart AND product must be Cookies OR product must be Cookies AND total must be greater than 500. 3.

Using Wildcards in Criteria Use wildcard characters to filter for a text string in a cell. The * wildcard The asterisk (*) wildcard character represents any number of characters in that position, including zero characters. In this example, any customer whose name contains "mart" will pass through the filter. The ? wildcard The question mark (?) wildcard character represents one characters in that position. In this example any 4-letter product that begins with c, and ends with ke, will pass through the filter. The ~ wildcard The tilde (~) wildcard character lets you search for characters that are used as wildcards. In this example any products that begins with Good and ends with Eats, will pass through the filter. To find only the product named Good*Eats, use a tilde character in front of the asterisk.

Criteria Examples
Extract Items in a Range

To extract a list of items in a range, you can use two columns for one of the fields (e.g. Date). If you enter two criteria on the same row in the criteria range, you create an AND statement. In this example, any records that are extracted must be greater than the first date AND less than the second date.

Create Two or More Sets of Conditions

If you enter criteria on different rows in the criteria range, you create an OR statement. In this example, extracted records must meet both conditions in row 2 OR both conditions in row 3.

Extract Items with Specific Text

When you use text as criteria with an advanced filter, Excel finds all items that begin with that text. For example, if you type "Ice" as a criterion, Excel finds "Ice", "Ice Cream" and "Ice Milk" To extract only the records for Ice, use the following format: ="=Ice" 2. Advanced Filters -- Complex Criteria For a zipped workbook with sample data and criteria,

Apply an Advanced Filter 1. Set up the database 1. The first row (A1:D1) has headings. 2. Subsequent rows contain data. 3. There are no blank rows within the database. 4. There is a blank row at the end of the database, and a blank column at the right. 2. Set up the Criteria Range (optional)

For a zipped workbook with sample data and criteria, click here.

In the criteria range, you can set the rules for the data that should remain visible after the filter is applied. You can use one criterion, or several. 1. In this example, cells F1:F2 are the criteria range. 2. The heading in F1 exactly matches a heading (D1) in the database. 3. Cell F2 contains the criterion. The > (greater than) operator is used, with the number 500 (no $ sign is included).. After the filter is applied, orders with a total greater than $500 will remain visible. Other operators include:

< less than <= less than or equal to >= greater than or equal to <> not equal to

3. Set up the Extract Range (optional) If you plan to copy the data to another location, you can specify the columns that you want to extract. If you want to extract ALL columns, you can leave the extract range empty. 1. Select the cell at the top left of the range for the extracted data. 2. Type the headings for the columns that you want to extract. These must be an exact match for the column headings, in spelling and punctuation. The column order can be different, and any or all of columns can be included. 4. Apply the Filter 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter. (In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. You can choose to filter the list in place, or copy the results to another location. 4. Excel should automatically detect the list range. If not, you can select the cells on the worksheet. 5. Select the criteria range on the worksheet 6. If you are copying to a new location, select a starting cell for the copy Note: If you copy to another location, all cells below the extract range will be cleared when the Advanced Filter is applied. 7. Click OK

Filter Unique Records You can use an Advanced Filter to extract a list of unique items in the database. For example, get a list of customers from an order list, or compile a list of products sold: Note: The list must contain a heading, or the first item may be duplicated in the results. 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. Choose 'Copy to another location'. 4. For the List range, select the column(s) from which you want to extract the unique values. 5. Leave the Criteria Range blank. 6. Select a starting cell for the Copy to location. 7. Add a check mark to the Unique records only box. 8. Click OK. Watch the Video View the steps described above, in a short video clip. Excel 2007 video

Extract Data to Another Worksheet If the database is on Sheet1 and you would like to extract data to Sheet2: 1. Go to Sheet 2 2. Select a cell in an unused part of the sheet (cell C4 in this example). 3. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 4. Choose Copy to another location. 5. Click in the List Range box 6. Select Sheet 1, and select the database. 7. (optional) Click in the Criteria range box. 8. Select the criteria range 9. Click in the Copy to box. 10. Select the cell on Sheet 2 in which you want the results to start, or select the headings that you have typed on Sheet 2. 11. (optional) Check the box for Unique Values Only 12. Click OK

Setting up the Criteria Range AND vs OR If a record meets all criteria on one row in the criteria area, it will pass through the filter. In example 1, at right -customer must be MegaMart AND product must be Cookies 1. AND total must be greater than 500. Criteria on different rows are joined with an OR operator. In the second example at right -customer must be MegaMart OR product must be Cookies OR total must be greater than 500. 2. By using multiple rows, you can combine the AND and OR operators. In the third example at right -customer must be MegaMart AND product must be Cookies OR product must be Cookies AND total must be greater than 500. 3. Using Wildcards in Criteria Use wildcard characters to filter for a text string in a cell. The * wildcard The asterisk (*) wildcard character represents any number of characters in that position, including zero characters. In this example, any customer whose name contains "mart" will pass through the filter. The ? wildcard The question mark (?) wildcard character represents one characters in that position. In this example any 4-letter product that begins with c, and ends with ke, will pass through the filter. The ~ wildcard The tilde (~) wildcard character lets you search for characters that are used as wildcards. In this example any products that begins with Good and ends with Eats, will pass through the filter. To find only the product named Good*Eats, use a tilde character in front

of the asterisk.

Criteria Examples
Extract Items in a Range

To extract a list of items in a range, you can use two columns for one of the fields (e.g. Date). If you enter two criteria on the same row in the criteria range, you create an AND statement. In this example, any records that are extracted must be greater than the first date AND less than the second date.
Create Two or More Sets of Conditions

If you enter criteria on different rows in the criteria range, you create an OR statement. In this example, extracted records must meet both conditions in row 2 OR both conditions in row 3.

Extract Items with Specific Text

When you use text as criteria with an advanced filter, Excel finds all items that begin with that text. For example, if you type "Ice" as a criterion, Excel finds "Ice", "Ice Cream" and "Ice Milk" To extract only the records for Ice, use the following format: ="=Ice" 2. Advanced Filters -- Complex Criteria For a zipped workbook with sample data and criteria, click here.

Excel -- Filters -- AutoFilter Basics


Use AutoFilter to hide some of the data in your worksheet. For example, you can focus on sales of a specific product, or print a list of your largest orders. Prepare the Database Filter the Database Remove a Filter Create a Custom Filter Prepare the Database 1. Set up the database a) The first row (A1:G1) has headings. b) Subsequent rows contain data. c) There are no blank rows within the database. d) There is a blank row at the end of the database, and a blank column at the right. 2. Turn on AutoFilter a) Select a cell in the database. b) From the Data menu, choose Filter, AutoFilter. A dropdown arrow appears beside each column heading. Filter the Database To filter the list, for example to view orders for one Product, choose a criterion from one of the dropdown lists. To further filter the list, choose from another column's dropdown list, e.g. Customer. Rows that don't meet the criteria will be hidden. Rows that remain visible have a blue number in the row button. The dropdown arrow for column(s) in which a criterion has been applied will also be blue. Remove a Filter To remove the filter, and leave AutoFilter turned on: In each column in which a filter has been applied, choose (All), the first item in the dropdown list OR From the Data menu, choose Filter, Show All To remove the current filter, and turn off
For a zipped workbook with sample data, click here.

AutoFilter: From the Data menu, choose Filter, AutoFilter

Special Filters Blank Cells in a Column If there are any blank cells in the column, the drop down list will contain two additional items -- (Blanks) and (NonBlanks). Filter Highest and Lowest Numbers To find the highest or lowest numbers in the table, choose (Top 10...) from the number column dropdown. 1. In the first box, choose Top or Bottom. 2. In the middle box, enter a number. 3. In the third box, choose Items or Percent. Note: The results are the highest or lowest values for the entire list, not the currently filtered list. If other columns are also filtered, you may see fewer than the specified number of items. Create a Custom Filter When you choose a criterion from a dropdown list, the list is filtered for rows that are equal to the criterion. If you need more options while filtering, you can choose (Custom...) from the dropdown list. This opens the Custom AutoFilter dialog box. To filter for one criterion: a) From the first dropdown list, select an operator. b) In the text box, type a value. c) Click OK.

To filter for two criteria: a) From the first dropdown list, select an operator. b) In the text box, type a value. c) Choose And or Or d) From the second dropdown list, select an operator. e) In the text box, type a value. f) Click OK. For a zipped workbook with sample data, click here. 1. AutoFilter Basics 2. AutoFilter Tips 3. AutoFilter Programming

Excel -- Filters -- AutoFilter Tips


AutoFilter Basics Some tips and techniques for working with AutoFilters, and some workarounds for problems you may encounter. Limits to Dropdown Lists Count of Filtered Records in Status Bar Filter for Text in a Long String Limits to Dropdown Lists An AutoFilter dropdown list will only show 1000 entries. As a result, in a large database, the AutoFilter dropdown may not show all the items in the column. You could add a new column, and use a formula to split the list into two groups, e.g.: =IF(LEFT(C2,1)<"N","A-M","N-Z") or to split the list into three groups, nest one IF formula inside another, e.g.: =IF(LEFT(C2,1)<"I","A-H",IF(LEFT(C2,1)<"Q","I-P","Q-Z"))

Or, for a column with thousands of unique entries, use a formula which extracts the first two or three letters, e.g.: =LEFT(C2,2) Filter on this column first, then by the intended criteria.

Count of Filtered Records in Status Bar Normally, after you have applied an AutoFilter, the Status Bar shows a count of visible records. Sometimes it just says, "Filter Mode." This can happen when your list has many formulas. There are articles in the Microsoft KnowledgeBase that explain:
XL2000: Excel AutoFilter Status Bar Message Shows "Filter Mode" Q213886) XL: AutoFilter Status Bar Message Shows "Filter Mode" (Q189479)

The Status Bar will also show "Filter Mode" if anything is changed in the list, after a filter has been applied. For example, if you format a cell, or type a number in one of the records, the 'Filter Mode' message will appear in the Status Bar. Workaround #1 -- Subtotal For a record count of the visible rows which contain data, you can use the Subtotal function in a formula in the same row as your headings. For example, to count the visible entries in column D which contain numbers, you could use this formula: =SUBTOTAL(2,D:D) The 2 in the first argument tells Excel to use the COUNT function on the visible cells in the range. To count rows that contain text, you could change the formula: =SUBTOTAL(3,C:C)-1 The 3 is for the COUNTA function, and the -1 removes one for the row which contains the column heading. NOTE: Blank cells will not be counted -- use a column with no blank cells. Workaround #2 -- Status Bar AutoCalc (from Excel MVP Dave Peterson) 1. Select a column that you know is non-empty. 2. Right-click on the embossed area of the status bar. 3. Choose Count -- it'll tell you how many are in the selected cells. 4. (If you included the header rows, subtract them.) To see how many total rows, choose Data>Filter>Show All, select a nice column and look at the bottom of the screen. The nice thing about this is you can get Min/Max/Average/etc. with

just simple mouse clicks and selections.

Filter for Text in a Long String You can use the Custom option to filter for cells that contain specific text. However, if the text is located after the 255th character in the cell, it won't be found. Also, the long text strings don't appear in the dropdown list in the heading cell. As a workaround, enter the search text string in a cell on the worksheet. Then add a formula to check for the text.

1. Insert a new column in the database, and in the heading cell, type the word you're searching for, e.g.: Shop 2. Enter the following formula in row 2 of the new column: =ISNUMBER(SEARCH($B$1,A2)) 3. Copy the formula down to the last row 4. Filter column B for TRUE 5. To filter for a different word, type a new string in cell B1, and reapply the filter in column B. Note: SEARCH is not case sensitive. For a case sensitive filter, use FIND, e.g.: =ISNUMBER(FIND($B$1,A2)) For a zipped workbook with sample data, click here. 1. AutoFilter Basics 2. AutoFilter Tips 3. AutoFilter Programming

Excel -- Filters -- AutoFilter Tips


AutoFilter Basics Some tips and techniques for working with AutoFilters, and some workarounds for problems you may encounter. Limits to Dropdown Lists Count of Filtered Records in Status Bar Filter for Text in a Long String Limits to Dropdown Lists An AutoFilter dropdown list will only show 1000 entries. As a result, in a large database, the AutoFilter dropdown may not show all the items in the column. You could add a new column, and use a formula to split the list into two groups, e.g.: =IF(LEFT(C2,1)<"N","A-M","N-Z") or to split the list into three groups, nest one IF formula inside another, e.g.: =IF(LEFT(C2,1)<"I","A-H",IF(LEFT(C2,1)<"Q","I-P","Q-Z")) Or, for a column with thousands of unique entries, use a formula which extracts the first two or three letters, e.g.: =LEFT(C2,2) Filter on this column first, then by the intended criteria.

Count of Filtered Records in Status Bar Normally, after you have applied an AutoFilter, the Status Bar shows a count of visible records. Sometimes it just says, "Filter Mode." This can happen when your list has many formulas. There are articles in the Microsoft KnowledgeBase that explain:
XL2000: Excel AutoFilter Status Bar Message Shows "Filter Mode" Q213886) XL: AutoFilter Status Bar Message Shows "Filter Mode" (Q189479)

The Status Bar will also show "Filter Mode" if anything is changed in the list, after a filter has been applied. For example, if you format a cell, or type a number in one of the records, the 'Filter Mode' message will appear in the Status Bar.

Workaround #1 -- Subtotal For a record count of the visible rows which contain data, you can use the Subtotal function in a formula in the same row as your headings. For example, to count the visible entries in column D which contain numbers, you could use this formula: =SUBTOTAL(2,D:D) The 2 in the first argument tells Excel to use the COUNT function on the visible cells in the range. To count rows that contain text, you could change the formula: =SUBTOTAL(3,C:C)-1 The 3 is for the COUNTA function, and the -1 removes one for the row which contains the column heading. NOTE: Blank cells will not be counted -- use a column with no blank cells. Workaround #2 -- Status Bar AutoCalc (from Excel MVP Dave Peterson) 1. Select a column that you know is non-empty. 2. Right-click on the embossed area of the status bar. 3. Choose Count -- it'll tell you how many are in the selected cells. 4. (If you included the header rows, subtract them.) To see how many total rows, choose Data>Filter>Show All, select a nice column and look at the bottom of the screen. The nice thing about this is you can get Min/Max/Average/etc. with just simple mouse clicks and selections. Filter for Text in a Long String You can use the Custom option to filter for cells that contain specific text. However, if the text is located after the 255th character in the cell, it won't be found. Also, the long text strings don't appear in the dropdown list in the heading cell. As a workaround, enter the search text string in a cell on the worksheet. Then add a formula to check for the text.

1. Insert a new column in the database, and in the heading cell, type the word you're searching for, e.g.: Shop 2. Enter the following formula in row 2 of the new column: =ISNUMBER(SEARCH($B$1,A2)) 3. Copy the formula down to the last row 4. Filter column B for TRUE 5. To filter for a different word, type a new string in cell B1, and reapply the filter in column B. Note: SEARCH is not case sensitive. For a case sensitive filter, use FIND, e.g.: =ISNUMBER(FIND($B$1,A2)) For a zipped workbook with sample data, click here. 1. AutoFilter Basics 2. AutoFilter Tips 3. AutoFilter Programming

Excel -- Filters -- AutoFilter Programming


AutoFilter Basics A few examples of controlling AutoFilters through VBA programming. Show All Records Turn On AutoFilter Turn Off AutoFilter Hide Filter Arrows Copy Filtered Rows AutoFilter on a Protected Worksheet Count Visible Rows Show All Records The following code shows all records, if a filter has been applied.
Sub ShowAllRecords() If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData End If End Sub

Turn On AutoFilter Use the following code to turn on an AutoFilter, if none exists
Sub TurnAutoFilterOn() 'check for filter, turn on if none exists If Not ActiveSheet.AutoFilterMode Then ActiveSheet.Range("A1").AutoFilter End If End Sub

Turn Off AutoFilter Use the following code to turn off an AutoFilter, if one exists
Sub TurnFilterOff() 'removes AutoFilter if one exists Worksheets("Data").AutoFilterMode = False End Sub

Hide Filter Arrows Perhaps you want users to filter only one of the columns in a table. The following procedure hides the arrows for all columns except column 2.
Sub HideArrows() 'hides all arrows except column 2 Dim c As Range Dim i As Integer i = Cells(1, 1).End(xlToRight).Column Application.ScreenUpdating = False For Each c In Range(Cells(1, 1), Cells(1, i)) If c.Column <> 2 Then c.AutoFilter Field:=c.Column, _ Visibledropdown:=False End If Next Application.ScreenUpdating = True End Sub

To show all the arrows, you can use the following code:
Sub ShowArrows() Dim c As Range Dim i As Integer i = Cells(1, 1).End(xlToRight).Column Application.ScreenUpdating = False For Each c In Range(Cells(1, 1), Cells(1, i)) c.AutoFilter Field:=c.Column, _ Visibledropdown:=True Next Application.ScreenUpdating = True End Sub

Copy Filtered Rows The following code copies the filtered rows from the active sheet to Sheet2.
Sub 'by Dim Dim CopyFilter() Tom Ogilvy rng As Range rng2 As Range

With ActiveSheet.AutoFilter.Range On Error Resume Next Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _ .SpecialCells(xlCellTypeVisible) On Error GoTo 0 End With If rng2 Is Nothing Then MsgBox "No data to copy" Else Worksheets("Sheet2").Cells.Clear Set rng = ActiveSheet.AutoFilter.Range rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _ Destination:=Worksheets("Sheet2").Range("A1") End If ActiveSheet.ShowAllData End Sub

AutoFilter on a Protected Worksheet You can use an AutoFilter on a protected worksheet, but you can't create an AutoFilter. Ensure that the filter is in place before the sheet is protected. In Excel 2002 and later versions, you can allow users to use AutoFilter when you set the worksheet protection. (see Protect Sheet dialog box at right) In previous versions of Excel, use a Workbook_Open macro to set the protection to user interface only. Store the following code on the ThisWorkbook module sheet. It also turns on the AutoFilter is one is not in place:
Private Sub Workbook_Open() 'check for filter, turn on if none exists With Worksheets("Data") If Not .AutoFilterMode Then .Range("A1").AutoFilter End If .EnableAutoFilter = True .Protect Password:="password", _ Contents:=True, UserInterfaceOnly:=True End With End Sub

To access the ThisWorkbook module, right-click the Excel icon to the left of the File menu, choose View

Code, and paste the code where the cursor is flashing.

Count Visible Rows You can display a message that shows a count of the rows that are visible after a filter has been applied:
Sub 'by Dim Set CountVisRows() Tom Ogilvy rng As Range rng = ActiveSheet.AutoFilter.Range

MsgBox rng.Columns(1). _ SpecialCells(xlCellTypeVisible).Count - 1 _ & " of " & rng _ .Rows.Count - 1 & " Records" End Sub

1. AutoFilter Basics 2. AutoFilter Tips 3. AutoFilter Programming

Excel -- Filters -- AutoFilter Programming


AutoFilter Basics A few examples of controlling AutoFilters through VBA programming. Show All Records Turn On AutoFilter Turn Off AutoFilter Hide Filter Arrows Copy Filtered Rows AutoFilter on a Protected Worksheet Count Visible Rows Show All Records The following code shows all records, if a filter has been applied.
Sub ShowAllRecords() If ActiveSheet.FilterMode Then ActiveSheet.ShowAllData End If End Sub

Turn On AutoFilter Use the following code to turn on an AutoFilter, if none exists
Sub TurnAutoFilterOn() 'check for filter, turn on if none exists If Not ActiveSheet.AutoFilterMode Then ActiveSheet.Range("A1").AutoFilter End If End Sub

Turn Off AutoFilter Use the following code to turn off an AutoFilter, if one exists
Sub TurnFilterOff() 'removes AutoFilter if one exists Worksheets("Data").AutoFilterMode = False End Sub

Hide Filter Arrows Perhaps you want users to filter only one of the columns in a table. The following procedure hides the arrows for all columns except column 2.
Sub HideArrows() 'hides all arrows except column 2 Dim c As Range Dim i As Integer i = Cells(1, 1).End(xlToRight).Column Application.ScreenUpdating = False For Each c In Range(Cells(1, 1), Cells(1, i)) If c.Column <> 2 Then c.AutoFilter Field:=c.Column, _ Visibledropdown:=False End If Next Application.ScreenUpdating = True End Sub

To show all the arrows, you can use the following code:
Sub ShowArrows() Dim c As Range Dim i As Integer i = Cells(1, 1).End(xlToRight).Column Application.ScreenUpdating = False For Each c In Range(Cells(1, 1), Cells(1, i)) c.AutoFilter Field:=c.Column, _ Visibledropdown:=True Next Application.ScreenUpdating = True End Sub

Copy Filtered Rows The following code copies the filtered rows from the active sheet to Sheet2.
Sub 'by Dim Dim CopyFilter() Tom Ogilvy rng As Range rng2 As Range

With ActiveSheet.AutoFilter.Range On Error Resume Next Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _ .SpecialCells(xlCellTypeVisible) On Error GoTo 0 End With If rng2 Is Nothing Then MsgBox "No data to copy" Else Worksheets("Sheet2").Cells.Clear Set rng = ActiveSheet.AutoFilter.Range rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _ Destination:=Worksheets("Sheet2").Range("A1") End If ActiveSheet.ShowAllData End Sub

AutoFilter on a Protected Worksheet You can use an AutoFilter on a protected worksheet, but you can't create an AutoFilter. Ensure that the filter is in place before the sheet is protected. In Excel 2002 and later versions, you can allow users to use AutoFilter when you set the worksheet protection. (see Protect Sheet dialog box at right) In previous versions of Excel, use a Workbook_Open macro to set the protection to user interface only. Store the following code on the ThisWorkbook module sheet. It also turns on the AutoFilter is one is not in place:
Private Sub Workbook_Open() 'check for filter, turn on if none exists With Worksheets("Data") If Not .AutoFilterMode Then .Range("A1").AutoFilter End If .EnableAutoFilter = True .Protect Password:="password", _ Contents:=True, UserInterfaceOnly:=True End With End Sub

To access the ThisWorkbook module, right-click the Excel icon to the left of the File menu, choose View

Code, and paste the code where the cursor is flashing.

Count Visible Rows You can display a message that shows a count of the rows that are visible after a filter has been applied:
Sub 'by Dim Set CountVisRows() Tom Ogilvy rng As Range rng = ActiveSheet.AutoFilter.Range

MsgBox rng.Columns(1). _ SpecialCells(xlCellTypeVisible).Count - 1 _ & " of " & rng _ .Rows.Count - 1 & " Records" End Sub

1. AutoFilter Basics 2. AutoFilter Tips 3. AutoFilter Programming

Excel -- Filters -- AutoFilter Tips


AutoFilter Basics Some tips and techniques for working with AutoFilters, and some workarounds for problems you may encounter. Limits to Dropdown Lists Count of Filtered Records in Status Bar Filter for Text in a Long String Limits to Dropdown Lists An AutoFilter dropdown list will only show 1000 entries. As a result, in a large database, the AutoFilter dropdown may not show all the items in the column. You could add a new column, and use a formula to split the list into two groups, e.g.: =IF(LEFT(C2,1)<"N","A-M","N-Z") or

to split the list into three groups, nest one IF formula inside another, e.g.: =IF(LEFT(C2,1)<"I","A-H",IF(LEFT(C2,1)<"Q","I-P","Q-Z")) Or, for a column with thousands of unique entries, use a formula which extracts the first two or three letters, e.g.: =LEFT(C2,2) Filter on this column first, then by the intended criteria.

Count of Filtered Records in Status Bar Normally, after you have applied an AutoFilter, the Status Bar shows a count of visible records. Sometimes it just says, "Filter Mode." This can happen when your list has many formulas. There are articles in the Microsoft KnowledgeBase that explain:
XL2000: Excel AutoFilter Status Bar Message Shows "Filter Mode" Q213886) XL: AutoFilter Status Bar Message Shows "Filter Mode" (Q189479)

The Status Bar will also show "Filter Mode" if anything is changed in the list, after a filter has been applied. For example, if you format a cell, or type a number in one of the records, the 'Filter Mode' message will appear in the Status Bar.

Workaround #1 -- Subtotal For a record count of the visible rows which contain data, you can use the Subtotal function in a formula in the same row as your headings. For example, to count the visible entries in column D which contain numbers, you could use this formula: =SUBTOTAL(2,D:D) The 2 in the first argument tells Excel to use the COUNT function on the visible cells in the range. To count rows that contain text, you could change the formula: =SUBTOTAL(3,C:C)-1 The 3 is for the COUNTA function, and the -1 removes one for the row which contains the column heading. NOTE: Blank cells will not be counted -- use a column with no blank cells. Workaround #2 -- Status Bar AutoCalc (from Excel MVP Dave Peterson) 1. Select a column that you know is non-empty. 2. Right-click on the embossed area of the status bar. 3. Choose Count -- it'll tell you how many are in the selected cells. 4. (If you included the header rows, subtract them.) To see how many total rows, choose Data>Filter>Show All, select a nice column and look at the bottom of the screen. The nice thing about this is you can get Min/Max/Average/etc. with just simple mouse clicks and selections. Filter for Text in a Long String You can use the Custom option to filter for cells that contain specific text. However, if the text is located after the 255th character in the cell, it won't be found. Also, the long text strings don't appear in the dropdown list in the heading cell. As a workaround, enter the search text string in a cell on the worksheet. Then add a formula to check for the text.

1. Insert a new column in the database, and in the heading cell, type the word you're searching for, e.g.: Shop 2. Enter the following formula in row 2 of the new column: =ISNUMBER(SEARCH($B$1,A2)) 3. Copy the formula down to the last row 4. Filter column B for TRUE 5. To filter for a different word, type a new string in cell B1, and reapply the filter in column B. Note: SEARCH is not case sensitive. For a case sensitive filter, use FIND, e.g.: =ISNUMBER(FIND($B$1,A2)) For a zipped workbook with sample data, click here. 1. AutoFilter Basics 2. AutoFilter Tips 3. AutoFilter Programming

Excel -- Worksheet Functions -- Sum Cells


Sum a range of cells -- SUM Sum a range of cells -- OFFSET Grand Total a range of cells Sum cells that match criteria -- SUMIF - Match criterion exactly - Match criterion in a string - Match criterion using operator Sum cells that match multiple criteria -- SUMPRODUCT Sum the Top 5 Numbers in a List Sum the Numbers in a Filtered List

AutoSum Download zipped sample workbook

Sum a range of cells -- SUM The SUM function will add the numbers in a range of cells. Its syntax is: =SUM(number1, number2,...number30). The arguments (e.g. number1) can be cell references, or typed into the formula. The following example uses one argument -- a reference to cells A1:A4. 1. Select the blank cell in the row below the cells that you want to sum, cell A5 in this example. 2. Click the AutoSum button on the Standard toolbar A SUM formula will appear in the active cell 3. Press the Enter key to complete the entry.
o

Note: Instead of using the AutoSum button, you could type the formula into the cell. Sum a range of cells -- OFFSET If you insert a row directly above the SUM formula in the previous example, the new row may not be included in the SUM. It may continue to sum cells A1:A4, and ignore A5. To ensure that new rows are included in the total, you can use the OFFSET function. 1. Select cell A5. 2. Enter the following formula: =SUM(A1:OFFSET(A5,-1,0)) 3. Press the Enter key to complete the entry. 4. Insert a row above row 5 5. Type a number in cell A5, and it will be included in the total in cell A6 Grand Total a range of cells You can calculate row totals, column totals, and a grand total for a range of cell, all in one step. 1. Select the range of cells, and the blank row below the range, and the blank cells in the column to the right (cells A1:D5 in the example at right) 2. Click the AutoSum button on the Standard toolbar
o

A SUM formula will be entered for each Total

Sum cells that match criteria -- SUMIF Match criterion exactly You can calculate a total for rows that meet a specific criterion. In this example only the rows with Pen orders will be included in the total. 1. 2. 3. 4. 5. 6. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked Type a comma, to separate the arguments Type the criterion. In this example, you're checking for text, so type the word in double quotes: "Pen" Note: upper and lower case are treated equally Type a comma, to separate the arguments Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed The completed formula is: =SUMIF(A2:A10,"Active",B2:B10)

7. 8. 9.

10. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10, B12, B2:B10) if cell B12 contained the text pen.

Match criterion in a string You can add cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be summed, because they contain the string "pen". 1. Select the cell in which you want to see the total (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: SUMIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters: "*Pen*" Note: upper and lower case are treated equally 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed 9. Type a closing bracket. The completed formula is: =SUMIF(A2:A10,"*Pen*",B2:B10) 10. Press the Enter key to complete the entry 11. The result will be 53, the total of rows that contain the string, "Pen" Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10,"*" & B12 & "*",B2:B10) if cell B12 contained the text pen.

Criterion and operator You can use an operator with a criterion. In this example only the rows where the number of sales reps is greater than or equal to ten will be included in the total. 1. 2. 3. 4. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells B2:B10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for rows where the number of visits is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes. 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum 9. Type a closing bracket. The completed formula is: =SUMIF(B2:B10,">=10",C2:C10) 10. Press the Enter key to complete the entry 11. The result will be 183, the total of rows with ten or more sales reps. Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(B2:B10,">=" & B12,C2:C10) if cell B12 contained the number 10. Sum cells that match multiple criteria -- SUMPRODUCT Match multiple criteria You can calculate a total for rows that meet two or more criteria. In this example only the rows where the status is "Active" and the number of visits is greater than or equal to ten will be included in the total.

1. 2. 3. 4.

Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMPRODUCT(--( Select the cells that contain the values to check for the first criterion. In this example, cells A2:A6 will be checked 5. Type the first criterion: ="Active" 6. Type ),--( 7. Select the cells that contain the values to check for the second criterion. In this example, cells B2:B6 will be checked 8. Type the second criterion: >=10 9. Type ),--( 10. Select the cells that contain the values to sum. In this example, cells C2:C6 will be summed 11. Finish with closing brackets: )) 12. The completed formula is: =SUMPRODUCT(--(A2:A6="Active"), --(B2:B6>=10),-(C2:C6)) 13. Press the Enter key to complete the entry

Sum the Top 5 Numbers in a List Use the SUM and LARGE functions together, to add the largest numbers in the list.

Version 1 -- Few Top Numbers


If a few numbers are to be summed, e.g. top 3, you can type the numbers into the formula. For example: =SUM(LARGE(A1:A7,{1,2,3})) The result is 70+60+50 = 180 Note: The second 50 is not included in the result, even though it is tied for 3rd place.

Version 2 -- Many Top Numbers


If many top numbers are to be summed you can include the INDIRECT function in the formula. In the INDIRECT function, use row numbers that represent the numbers you want to include. In this example, rows 1:10 are used, so the top 10 numbers in the referenced range will be summed. 1. Type the formula: =SUM(LARGE(A1:A50,ROW(INDIRECT("1:10")))) 2. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter

Version 3 -- Variable Top Numbers


If a variable number of top numbers are to be summed you can include the INDIRECT function in the formula, as shown above, and refer to a cell that holds the variable.. 1. In cell C1, type the number of top cells, e.g. 10 2. Type the formula: =SUM(LARGE(A1:A7,ROW(INDIRECT("1:"&C1)))) 3. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter Sum the Numbers in a Filtered List After you filter the rows in a list, you can use the SUBTOTAL function to sum the numbers in the visible rows. 1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics 2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders. 3. Select the cell immediately below the column you want to sum. 4. Click the AutoSum button on the Excel's Standard toolbar. o If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button. 5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column o The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. There is a 9 in this example, which tells Excel to SUM the numbers.

Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list. 6. Press the Enter key to complete the formula entry.
o

Note: In Excel 2003, you can use the formula: =SUBTOTAL(109,B2:B9) to subtotal visible cells in a range where rows have been manually hidden, or filtered. Download zipped sample workbook

Worksheet Functions -- Sum Cells Worksheet Functions -- VLOOKUP Worksheet Functions -- INDEX / MATCH Worksheet Functions -- Count Cells Worksheet Functions -- INDIRECT

Answers to Frequently Asked Questions about Microsoft Excel

Worksheet Functions and Formats


1. Functions 1. Is there a formula that will round a value to the nearest increment of 5? 2. What formula will look at a cell, find that value in another sheet and return data
from an adjacent column.

3. I want to add the largest/smallest 5 entries in A column. 4. How do I pick 20 random items from a list of 100?

5. 6. 7. 8.

Is it possible to write a SUMIF worksheet formula to sum visible cells only? How do I enter two criteria so I can sum numbers between 5 and 10? Why does my function display #NAME? Is there a way of returning the name of a sheet in a cell without using code?

2. Calculation 1. My spreadsheet does not calculate correctly ! I'm right, Excel's wrong! 2. My spreadsheet does not calculate at all! 3. The formulas are showing, instead of the results 3. Working with Tables and Lists 1. I have data stored in rows and I want to change these rows to columns 2. Using Data>Subtotals, I would like to create a table with just these subtotals, not
the detail rows.

3. When I use AutoFilter I don't see all the items in the drop down list. Why not? 4. In a cell I have "lastname, firstname". I want lastname in one cell and first name in
another.

5. I want to fix a cell so the user can only choose from a list 4. Formatting 1. Is there a way to make a cell turn red, based on the value in another cell?

Beyond the Keyboard


After you spend all day working at the computer, it's nice to explore other topics. Here are links to a few of the things that interest me.

I'm still working on this section, so please check back later for additions and updates.

Reading
During the long Canadian winter, or on a hot summer day, it's relaxing to curl up with a good book. This page has a list of reading related links.

Gardening
An enjoyable summer activity is gardening. You can see the progress (or lack of progress) of my garden.

Cooking
I have a fairly large collection of cookbooks, and am especially interested in Canadian

Excel -- Data Entry -- Fill Blank Cells


Fill Blank Cells Fill Blank Cells Programmatically

Fill Blank Cells Some worksheets contain cells that have been left blank, in order to make the headings and subheadings easier to read. However, if you want to sort or filter the list, you need to fill in the blanks, by copying the value from the first filled cell above the blank. The following technique makes it easy to fill in the blanks. Watch the Video View the steps described below, in a short video clip.

Start by selecting the empty cells:


1. Select the cells in the column, starting in the row below the column heading. 2. Choose Edit | Go To 3. Click the Special button 4. Select Blanks, click OK

Enter the formula to copy the value:


1. Type an equal sign 2. Press the up arrow on the keyboard -- this will enter a reference to the cell above -- cell A2 in this example 3. Hold the Ctrl key and press Enter -- this enters the formula in all selected cells

Change the formulas to values:


In order to sort or filter the data, the formulas must be changed to values. 1. Select the entire column 2. Choose Edit | Copy 3. With the column still selected, choose Edit | Paste Special 4. Select Values, click OK Note: Do this carefully if there are other cells in the range which contain formulas. Watch the Video View the steps described above, in a short video clip.

Fill Blank Cells Programmatically If you frequently have to fill blank cells, you may prefer to use a macro. The following code will fill blank cells in the active column:
Sub FillColBlanks() 'by Dave Peterson 2004-01-06 'fill blank cells in column with value above Dim wks As Worksheet Dim rng As Range Dim LastRow As Long Dim col As Long Set wks = ActiveSheet With wks col = activecell.column 'or 'col = .range("b1").column Set rng = .UsedRange 'try to reset the lastcell LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row Set rng = Nothing On Error Resume Next Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _ .Cells.SpecialCells(xlCellTypeBlanks ) On Error GoTo 0 If rng Is Nothing Then MsgBox "No blanks found" Exit Sub Else rng.FormulaR1C1 = "=R[-1]C" End If 'replace formulas with values With .Cells(1, col).EntireColumn .Value = .Value End With End With End Sub

1. Data Entry -- Tips 2. Data Entry -- Fill Blank Cells 3. Data Entry -- Convert Text to Numbers 4. Data Entry -- Increase Numbers With Paste Special

Excel -- Comments -- Basics


Add comments to worksheets cells, to explain the contents, or to offer tips to users. Insert a Comment Display a Specific Comment Display All Comments Use the Reviewing Toolbar Format Text in a Comment Printing Comments Comments -- Tips Comments -- Programming Insert a Comment 1. Select the cell in which you want the comment. 2. Choose Insert|Comment 3. Type your comment where the cursor is flashing. 4. Text will wrap automatically. If you want to start a new line, press the Enter key. 5. When finished, click outside the comment box Display a Specific Comment 1. Right-click the cell which contains the comment. 2. Choose Show Comment To hide the comment: 1. Right-click the cell which contains the comment. 2. Choose Hide Comment Display All Comments 1. Choose View|Comments Note: All comments in all open workbooks will be displayed. 2. To hide the comments, choose View|Comment

Use the Reviewing Toolbar If you're doing extensive work with comments, you might save time by using the Reviewing Toolbar. Use its buttons, instead of choosing commands from the Menu Bar. 1. To open the Reviewing toolbar, choose View|Toolbars 2. If the active cell contains a comment, the Reviewing Toolbar displays the following Comment buttons: a) Edit comment b) Previous comment c) Next comment d) Show comment e) Show all comments f) Delete comment

3. If the active cell does not contain a comment, the Reviewing Toolbar displays the following Comment buttons: a) New comment b) Previous comment c) Next comment d) N/A e) Show all comments f) N/A

Format Text in a Comment You can change the font, the font size, font colour and font style, for all or part of a comment. 1. Right-click the cell which contains the comment. 2. Choose Edit Comment 3. To format all text, click on the border of the comment shape. To format specific text within the comment, drag over the text to select it. 4. Use the Font tools on the Formatting toolbar to modify the text appearance 5. When finished, click outside the comment box.

Printing Comments You can print comments as displayed on the worksheet, or print them at the end of the worksheet To print as displayed: 1. Show specific comments or all comments. 2. Choose File|Page Setup 3. On the Sheet tab, from the Comments dropdown, choose 'As displayed on sheet'. 4. Click Ok 5. Choose File|Print (or click the Print button) To print at the end of the worksheet: 1. Choose File|Page Setup 2. On the Sheet tab, from the Comments dropdown, choose 'At end of sheet'. 3. Click Ok 4. Choose File|Print (or click the Print button) To print a worksheet with comment indicators: See instructions in Comments -- Programming 1. Comments -- Basics 2. Comments -- Tips 3. Comments -- Programming

Excel -- Comments -- Tips


Some tips for working with comments. Change the User Name Change Comment Shape Add a Picture to a Comment Change the default Font Size Change the Comment Indicator Colour

Alternative to Cell Comments

Change the User Name Instead of showing the user name at the start of a comment, you can change to something generic, such as "Note:" However, this change affects the User Name in all Microsoft Office programs, so you may want to reset the name before you exit Excel. 1. Choose Tools|Options 2. Select the General tab 3. Delete the existing User Name, and type a new entry 4. Click OK Change the Comment Shape Add a bit of interest to a worksheet, by changing the comment shape from a rectangle. 1. Right-click the cell which contains the comment. 2. Choose Edit Comment 3. Click on the border of the comment, to select it. 4. On the Drawing toolbar, click the Draw button 5. Choose Change AutoShape, and choose a category. 6. Click on a shape to select it. 7. When finished, click outside the comment. Add a Picture to a Comment 1. Right-click the cell which contains the comment. 2. Choose Show/Hide Comments, and clear any text from the comment. 3. Click on the border of the comment, to select it. 4. Choose Format|Comment 5. On the Colors and Lines tab, click the dropdown arrow for Color. 6. Click Fill Effects 7. On the picture tab, click Select Picture 8. Locate and select the picture 9. To keep the picture in proportion, add a check mark to Lock Picture Aspect Ratio 10. Click Insert, click OK, click OK

Watch the steps in a short video.

Change the Default Font Size You can change the font size of new comments by changing the settings in your Control Panel. (Instructions for Windows XP) 1. Right-click on the desktop, and choose Properties 2. On the Appearance tab, click Advanced. 3. From the Item dropdown, choose Tooltip 4. Choose a font Size, click OK, click OK (Note: selecting a font type here will not affect the default font used in Excel's comments)

Change the Comment Indicator Colour Comment indicators are red, and there's no option to change that setting. As a workaround, you can draw triangular shapes over the indicators, and fill them with a different colour from the palette. For instructions, see Comments -- Programming Alternative to Cell Comments Add a comment to a Data Validation Input Message, and it can be displayed when you tab to the cell. 1. 2. 3. 4. 5. Select the cell in which you want to see the message Choose Data|Data Validation Click on the Input Message tab to activate it Add a check mark to 'Show input message when cell is selected' Type your message heading text in the Title box. This text will appear in bold print at the top of the message. 6. Type your message in the Input message box. 7. Click OK

Excel -- Comments -- Tips


Some tips for working with comments. Change the User Name Change Comment Shape Add a Picture to a Comment Change the default Font Size Change the Comment Indicator Colour Alternative to Cell Comments

Change the User Name Instead of showing the user name at the start of a comment, you can change to something generic, such as "Note:" However, this change affects the User Name in all Microsoft Office programs, so you may want to reset the name before you exit Excel. 1. Choose Tools|Options 2. Select the General tab 3. Delete the existing User Name, and type a new entry 4. Click OK Change the Comment Shape Add a bit of interest to a worksheet, by changing the comment shape from a rectangle. 1. Right-click the cell which contains the comment. 2. Choose Edit Comment 3. Click on the border of the comment, to select it. 4. On the Drawing toolbar, click the Draw button 5. Choose Change AutoShape, and choose a category. 6. Click on a shape to select it. 7. When finished, click outside the comment.

Add a Picture to a Comment 1. Right-click the cell which contains the comment. 2. Choose Show/Hide Comments, and clear any text from the comment. 3. Click on the border of the comment, to select it. 4. Choose Format|Comment 5. On the Colors and Lines tab, click the dropdown arrow for Color. 6. Click Fill Effects 7. On the picture tab, click Select Picture 8. Locate and select the picture 9. To keep the picture in proportion, add a check mark to Lock Picture Aspect Ratio 10. Click Insert, click OK, click OK Watch the steps in a short video. Change the Default Font Size You can change the font size of new comments by changing the settings in your Control Panel. (Instructions for Windows XP) 1. Right-click on the desktop, and choose Properties 2. On the Appearance tab, click Advanced. 3. From the Item dropdown, choose Tooltip 4. Choose a font Size, click OK, click OK (Note: selecting a font type here will not affect the default font used in Excel's comments)

Change the Comment Indicator Colour Comment indicators are red, and there's no option to change that setting. As a workaround, you can draw triangular shapes over the indicators, and fill them with a different colour from the palette. For instructions, see Comments -- Programming

Alternative to Cell Comments Add a comment to a Data Validation Input Message, and it can be displayed when you tab to the cell. 1. Select the cell in which you want to see the message 2. Choose Data|Data Validation 3. Click on the Input Message tab to activate it 4. Add a check mark to 'Show input message when cell is selected' 5. Type your message heading text in the Title box. This text will appear in bold print at the top of the message. 6. Type your message in the Input message box. 7. Click OK 1. Comments -- Basics 2. Comments -- Tips 3. Comments -- Programming

Excel -- Comments -- Programming


You can add any of the following macros to a workbook that opens automatically when Excel opens (e.g. Personal.xls), then add a toolbar button or shortcut key to run it. Change the User Name Insert a Plain Comment Insert a Formatted Comment Insert a Comment with Date and Time Replace Old Name in Comments Reset Comments to Original Position Resize Comments Format All Comments Show Comments on Active Sheet Show Comment in Centre of Active Window Copy Comment Text to Adjacent Cell Copy Comments to Another Worksheet Copy Comments from All Sheets to Another Worksheet Copy Comments to Microsoft Word Print Comments with Indicators Number and List Comments Insert Selected Picture Into Comment

Change the User Name Instead of showing the user name at the start of a comment, you can change to something generic, such as "Note:" However, this change affects the User Name in all Microsoft Office programs, so you may want to reset the name before you exit Excel. To set a generic label:
Sub CommentNote() Application.UserName = "Note" End Sub

To reset the User Name:


Sub CommentName() Application.UserName = "John Smith" End Sub

Insert a Plain Comment To insert a comment with no User Name, use the following macro. Note: Because the macro contains a SendKeys command, it should be run with the worksheet active, not Visual Basic Explorer.
Sub CommentAddOrEdit() 'adds new plain text comment or positions 'cursor at end of existing comment text Dim cmt As Comment Set cmt = ActiveCell.Comment If cmt Is Nothing Then ActiveCell.AddComment text:="" End If SendKeys "%ie~" End Sub

To avoid use of the SendKeys command, you can use the following variation, which leaves the comments visible. After running the macro, the comment shape is selected. Start typing, and the text will be added to the comment box, or to the end of the existing comment text.
Sub CommentAddOrEdit() 'method suggested by Jon Peltier 2006-03-04 'adds new plain text comment or adds text 'at end of existing comment text Dim cmt As Comment Set cmt = ActiveCell.Comment If cmt Is Nothing Then Set cmt = ActiveCell.AddComment cmt.text text:="" End If 'type to add comment text to selected shape cmt.Visible = True cmt.Shape.Select

End Sub

Replace Old Name in Comments If a previous user inserted comments, their name may appear at the top of the comment. Their name may also appear in the Status Bar, when you hover over the cell that contains a comment. The following macro will replace the old name with a new name.
Sub ChangeCommentName() 'replaces old names in comments 'deletes and reinserts comments ' so new name appears in status bar Dim ws As Worksheet Dim cmt As Comment Dim strOld As String Dim strNew As String Dim strComment As String strNew = "New Name" strOld = "Old Name" Application.UserName = strNew For Each ws In ActiveWorkbook.Worksheets For Each cmt In ws.Comments strComment = Replace(cmt.text, strOld, strNew) cmt.Delete cmt.Parent.AddComment text:=strComment Next cmt Next ws End Sub

Insert a Formatted Comment To insert a comment with no User Name, formatted in Times New Roman font, use the following macro:
Sub CommentAddOrEditTNR() 'adds TimesNewRoman comment or positions 'cursor at end of existing comment text Dim cmt As Comment Set cmt = ActiveCell.Comment If cmt Is Nothing Then ActiveCell.AddComment text:="" Set cmt = ActiveCell.Comment With cmt.Shape.TextFrame.Characters.Font .Name = "Times New Roman" .Size = 11 .Bold = False .ColorIndex = 0 End With End If SendKeys "%ie~" End Sub

Insert a Comment with Date and Time To insert a comment with the current date and time, or append the current date and time to an existing comment, use the following macro:
Sub CommentDateTimeAdd() 'adds comment with date and time, ' positions cursor at end of comment text Dim strDate As String Dim cmt As Comment strDate = "dd-mmm-yy hh:mm:ss" Set cmt = ActiveCell.Comment If cmt Is Nothing Then Set cmt = ActiveCell.AddComment cmt.text text:=Format(Now, strDate) & Chr(10) Else cmt.text text:=cmt.text & Chr(10) _ & Format(Now, strDate) & Chr(10) End If With cmt.Shape.TextFrame .Characters.Font.Bold = False End With SendKeys "%ie~" End Sub

Reset Comments to Original Position If comments have moved out of position, you can reset them using the following code:
Sub ResetComments() Dim cmt As Comment For Each cmt In ActiveSheet.Comments cmt.Shape.Top = cmt.Parent.Top + 5 cmt.Shape.Left = _ cmt.Parent.Offset(0, 1).Left + 5 Next End Sub

Resize Comments If comments have changed size, you can reset them using the following code. The first macro resizes all comments on the active sheet, and the second macro resizes all comments in the selected range.

Resize all comments on the active sheet


Sub Comments_AutoSize() 'posted by Dana DeLouis 2000-09-16 Dim MyComments As Comment Dim lArea As Long For Each MyComments In ActiveSheet.Comments With MyComments .Shape.TextFrame.AutoSize = True If .Shape.Width > 300 Then lArea = .Shape.Width * .Shape.Height .Shape.Width = 200 ' An adjustment factor of 1.1 seems to work ok. .Shape.Height = (lArea / 200) * 1.1 End If End With Next ' comment End Sub

Resize all comments in the selected area


Sub ResizeCommentsInSelection() 'Posted by Dave Peterson 2002-02-25 Dim mycell As Range Dim myRng As Range Dim lArea As Long Set myRng = Selection For Each mycell In myRng.Cells If Not (mycell.Comment Is Nothing) Then With mycell.Comment .Shape.TextFrame.AutoSize = True If .Shape.Width > 300 Then lArea = .Shape.Width * .Shape.Height .Shape.Width = 200 .Shape.Height = (lArea / 200) * 1.2 End If End With End If Next mycell End Sub

Format All Comments After you have inserted comments in a workbook, you can use the following code to change the font and font size for all comments in the workbook.
Sub FormatAllComments() Dim ws As Worksheet Dim cmt As Comment For Each ws In ActiveWorkbook.Worksheets For Each cmt In ws.Comments With cmt.Shape.TextFrame.Characters.Font .Name = "Times New Roman" .Size = 12 End With Next cmt Next ws End Sub

Show Comments on Active Sheet If you choose View|Comments, all comments in all open workbooks will be displayed. Instead, you can use code to show the comments on one sheet, and display the comment indicators only on other sheets.
Sub ShowSheetComments() 'shows all comments on the active sheet Dim c As Comment For Each c In ActiveSheet.Comments c.Visible = True Next End Sub

Show Comments in Centre of Active Window Paste the following code onto a worksheet module. If a cell with a comment is selected on that sheet, its comment is displayed in the centre of the active window's visible range.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'www.contextures.com/xlcomments03.html Dim rng As Range Dim cTop As Long Dim cWidth As Long Dim cmt As Comment Dim sh As Shape Application.DisplayCommentIndicator _ = xlCommentIndicatorOnly Set rng = ActiveWindow.VisibleRange cTop = rng.Top + rng.Height / 2 cWidth = rng.Left + rng.Width / 2 If ActiveCell.Comment Is Nothing Then 'do nothing Else Set cmt = ActiveCell.Comment Set sh = cmt.Shape sh.Top = cTop - sh.Height / 2 sh.Left = cWidth - sh.Width / 2 cmt.Visible = True End If End Sub

Copy Comment Text to Adjacent Cell The following macro will copy comment text to the cell to the right, if that cell is empty.
Sub ShowCommentsNextCell() 'based on code posted by Dave Peterson 2003-05-16

Application.ScreenUpdating = False Dim commrange As Range Dim mycell As Range Dim curwks As Worksheet Set curwks = ActiveSheet On Error Resume Next Set commrange = curwks.Cells _ .SpecialCells(xlCellTypeComments) On Error GoTo 0 If commrange Is Nothing Then MsgBox "no comments found" Exit Sub End If For Each mycell In commrange If mycell.Offset(0, 1).Value = "" Then mycell.Offset(0, 1).Value = mycell.Comment.Text End If Next mycell Application.ScreenUpdating = True End Sub

Copy Comments to Another Worksheet The following macro will add a sheet to the workbook, with a list of comments, including the cell address, and cell name, if any.

Sub showcomments() 'posted by Dave Peterson 2003-05-16 Application.ScreenUpdating = False Dim Dim Dim Dim Dim commrange mycell As curwks As newwks As i As Long As Range Range Worksheet Worksheet

Set curwks = ActiveSheet On Error Resume Next Set commrange = curwks.Cells _ .SpecialCells(xlCellTypeComments) On Error GoTo 0 If commrange Is Nothing Then MsgBox "no comments found" Exit Sub End If Set newwks = Worksheets.Add newwks.Range("A1:D1").Value = _ Array("Address", "Name", "Value", "Comment") i = 1 For Each mycell In commrange With newwks i = i + 1 On Error Resume Next .Cells(i, 1).Value = mycell.Address .Cells(i, 2).Value = mycell.Name.Name .Cells(i, 3).Value = mycell.Value .Cells(i, 4).Value = mycell.Comment.Text End With Next mycell Application.ScreenUpdating = True End Sub

Copy Comments from All Sheets to Another Worksheet The following macro will add a sheet to the workbook, with a list of comments from all sheets in the workbook, including the sheet name, cell address, and cell name, if any.
Sub ShowCommentsAllSheets() 'modified from code 'posted by Dave Peterson 2003-05-16 Application.ScreenUpdating = False Dim Dim Dim Dim Dim commrange As Range mycell As Range ws As Worksheet newwks As Worksheet i As Long

Set newwks = Worksheets.Add newwks.Range("A1:E1").Value = _ Array("Sheet", "Address", "Name", "Value", "Comment") For Each ws In ActiveWorkbook.Worksheets On Error Resume Next Set commrange = ws.Cells.SpecialCells(xlCellTypeComments) On Error GoTo 0 If commrange Is Nothing Then 'do nothing Else i = newwks.Cells(Rows.Count, 1).End(xlUp).Row For Each mycell In commrange With newwks i = i + 1 On Error Resume Next .Cells(i, 1).Value = ws.Name .Cells(i, 2).Value = mycell.Address .Cells(i, 3).Value = mycell.Name.Name .Cells(i, 4).Value = mycell.Value .Cells(i, 5).Value = mycell.Comment.text End With Next mycell End If Set commrange = Nothing Next ws 'format cells for no wrapping, remove line break newwks.Cells.WrapText = False newwks.Columns("E:E").Replace What:=Chr(10), _ Replacement:=" ", LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, _ SearchFormat:=False, ReplaceFormat:=False Application.ScreenUpdating = True End Sub

Copy Comments to Microsoft Word The following code copies the comment text from the active sheet, and adds it to a Microsoft Word document, along with the cell address.
Sub CopyCommentsToWord() Dim cmt As Comment Dim WdApp As Object On Error Resume Next Set WdApp = GetObject(, "Word.Application") If Err.Number <> 0 Then Err.Clear Set WdApp = CreateObject("Word.Application") End If With WdApp .Visible = True .Documents.Add DocumentType:=0 For Each cmt In ActiveSheet.Comments .Selection.TypeText cmt.Parent.Address _ & vbTab & cmt.Text .Selection.TypeParagraph Next End With Set WdApp = Nothing End Sub

Print Worksheet with Comment Indicators When you print a worksheet that contains comments, the comment indicators are not visible. There is no option to change this behaviour. As a workaround, you can draw triangle AutoShapes over the comment indicators. Draw Triangular AutoShapes over the Comment Indicators The following code will draw a triangular AutoShape over each comment indicator on the active sheet:
Sub Dim Dim Dim Dim Dim Dim CoverCommentIndicator() ws As Worksheet cmt As Comment rngCmt As Range shpCmt As Shape shpW As Double 'shape width shpH As Double 'shape height

Set ws = ActiveSheet shpW = 6 shpH = 4 For Each cmt In ws.Comments Set rngCmt = cmt.Parent With rngCmt Set shpCmt = ws.Shapes.AddShape(msoShapeRightTriangle, _ rngCmt.Offset(0, 1).Left - shpW, .Top, shpW, shpH) End With With shpCmt .Flip msoFlipVertical .Flip msoFlipHorizontal .Fill.ForeColor.SchemeColor = 10 'Red '12=Blue, 57=Green .Fill.Visible = msoTrue .Fill.Solid .Line.Visible = msoFalse End With Next cmt End Sub

Remove Triangular AutoShapes over the Comment Indicators The following code will remove the triangular AutoShape over each comment indicator on the active sheet:
Sub RemoveIndicatorShapes() Dim ws As Worksheet Dim shp As Shape Set ws = ActiveSheet For Each shp In ws.Shapes If Not shp.TopLeftCell.Comment Is Nothing Then If shp.AutoShapeType = _ msoShapeRightTriangle Then shp.Delete

Number and List Comments When you print a worksheet that contains comments, you can use programming to number the comments. List the numbered comments on a separate sheet, and print them. Download the zipped sample file for numbered comments: CommentsNumberPrint.zip Draw Numbered Rectangles over the Comment Indicators The following code will draw a numbered rectangle AutoShape over each comment indicator on the active sheet:
Sub Dim Dim Dim Dim Dim Dim Dim CoverCommentIndicator() ws As Worksheet cmt As Comment lCmt As Long rngCmt As Range shpCmt As Shape shpW As Double 'shape width shpH As Double 'shape height = ActiveSheet 8 6 1

Set ws shpW = shpH = lCmt =

For Each cmt In ws.Comments Set rngCmt = cmt.Parent With rngCmt Set shpCmt = ws.Shapes.AddShape(msoShapeRectangle, _ rngCmt.Offset(0, 1).Left - shpW, .Top, shpW, shpH) End With With shpCmt With .Fill .ForeColor.SchemeColor = 9 'white .Visible = msoTrue .Solid End With With .Line .Visible = msoTrue .ForeColor.SchemeColor = 64 'automatic .Weight = 0.25 End With With .TextFrame .Characters.Text = lCmt .Characters.Font.Size = 5 .Characters.Font.ColorIndex = xlAutomatic .MarginLeft = 0# .MarginRight = 0# .MarginTop = 0# .MarginBottom = 0# .HorizontalAlignment = xlCenter End With .Top = .Top + 0.001 End With lCmt = lCmt + 1 Next cmt End Sub

Insert Selected Picture Into Comment The following code creates a file from the selected picture, inserts it into a comment in the active cell, and deletes the picture. Download the zipped sample file.
Sub PictureIntoComment() Dim ch As ChartObject Dim dWidth As Double Dim dHeight As Double Dim ws As Worksheet Dim sName As String Dim cmt As Comment Dim sPath As String Dim sFile As String Dim rng As Range Set ws = ActiveSheet Set rng = ActiveCell sPath = ThisWorkbook.Path & "\" sName = InputBox("Name for picture file (no extension)", "File Name") If sName = "" Then sName = "Picture_" & Format(Date, "yyyymmdd") sFile = sPath & sName & ".gif" dWidth = Selection.Width dHeight = Selection.Height Selection.Cut Set ch = ws.ChartObjects.Add(Left:=rng.Left, Top:=rng.Top, _ Width:=dWidth, Height:=dHeight) ch.Chart.Paste rng.Activate ch.Chart.Export sFile ch.Delete Set cmt = rng.AddComment cmt.Text Text:="" With cmt.Shape .Fill.UserPicture sFile .Width = dWidth .Height = dHeight End With End Sub

1. Comments -- Basics 2. Comments -- Tips 3. Comments -Programming

Excel -- Conditional Formatting --

Introduction
1. Conditional Formatting -- Introduction a. What is Conditional Formatting? b. Apply Conditional Formatting to a Cell 2. Conditional Formatting -- Based on another cell 3. Conditional Formatting -- Examples Download a zipped sample file To view the steps in a short video, click here What is Conditional Formatting? Conditional formatting allows you to set rules for cell formatting. If the rules (conditions) are met, then the formatting is applied. You can have up to 3 rules in a cell. For example, you can set conditional formatting so that a cell turns blue if it contains a value higher than 75 and turns green if it contains a value lower than 50. Apply Conditional Formatting to a Cell 1. Select the cells to be formatted 2. Choose Format>Conditional Formatting... 3. Leave the first drop-down box set to Cell Value Is 4. In the second drop-down box, choose one of the operators. In this example, choose 'greater than' 5. In the text box, type a number or a cell reference. In this example, type the value you want to check -- 75.

6. Click the Format button 7. On the Patterns tab, select a colour for the conditional formatting -- blue, in this example. You can also choose a Font format or a cell Border. 8. Click OK.

9. To add another conditional format, click the Add button. 10. Repeat steps 3 to 8, using the values and colours for the second conditional format. 11. Click OK, to return to the worksheet.

Download a zipped sample file To view the steps in a short video, click here 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Based on another cell 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Conditional Formatting -- Examples


Hide Errors Hide Duplicate Values Highlight Duplicates in Column Highlight Items in a List Highlight Lottery Numbers Highlight Upcoming Expiry Dates Hide Cell Contents When Printing Shade Alternating Rows Shade Bands of Rows Shade Alternating Filtered Rows Create Coloured Shapes Hide Errors You can use conditional formatting to check for errors, and change the font colour to match the cell colour. In this example, if column B contains a zero, the #DIV/0! error is displayed in column C. 1. Select cells C2:C5 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter a formula that refers to the active cell in the selection: =ISERROR(C2) or, to hide only #N/A errors: =ISNA(C2) 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK download a zipped sample file

Hide Duplicate Values In a table, each row should have all data entered, to enable sorting and filtering. However, you can hide the duplicate values, to make the list easier to read. In this example, when the table is sorted by Region, the second (and subsequent) occurences of each region name will have white font colour. 1. 2. 3. 4. Select range A2:A5 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =A2=A1 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK Highlight Duplicates in Column Use conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK Highlight Items in a List Use conditional formatting to highlight items that are in a list on the worksheet.: 1. Create a list of items you want to highlight. If the items are on a different sheet than the conditional formatting, name the list. 2. Select range A2:A7 3. Choose Format|Conditional Formatting 4. From the first dropdown, choose Formula Is 5. For the formula, enter =COUNTIF($C$2:$C$4,A2) or, if the list is named, use the name in the formula: =COUNTIF(CodeList,A2) 6. Click the Format button. 7. Select a font colour for highlighting. 8. Click OK, click OK

Highlight Lottery Numbers You can highlight the ticket numbers that have been drawn in a lottery. In this example the ticket numbers are in cells B2:G4, and the drawn numbers are entered in cells B6:G6 1. 2. 3. 4. Select cells B2:G4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the CountIf function: =COUNTIF($B$6:$G$6,B2) 5. Click the Format button. 6. Select formatting options (green pattern, in this example), click OK 7. Click OK Highlight Upcoming Expiry Dates You can highlight payments that are due in the next thirty days. In this example, Due dates are entered in cells A2:A4. 1. 2. 3. 4. Select cells A2:A4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the Today function count the days: =AND(A2-TODAY()>=0,A2-TODAY()<=30) 5. Click the Format button. 6. Select formatting options (Bold, Blue font, in this example), click OK 7. Click OK Hide Cell Contents When Printing You can use conditional formatting to hide cells when printing. In this example, the contents of cells B2:F4 are changed to white font, if cell H1 contains an x. To print with the cell contents hidden, type an x in cell H1. To display the cell contents, delete the x in cell H1. 1. 2. 3. 4. 5. 6. Select cells B2:F4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =$H$1="x" Click the Format button. Select formatting options (white font and white pattern, in this example)

7. Click OK, click OK

Shade Alternating Rows You can use conditional formatting to shade alternating rows on the worksheet. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Bands of Rows You can use conditional formatting to shade bands of rows on the worksheet. In this example, 3 rows are shaded light grey, and 3 are left with no shading. In the MOD function, the total number of rows in the set of banded rows (6) is entered. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),6)<3 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Alternating Filtered Rows You can use conditional formatting to shade alternating rows in a filtered list. 1. 2. 3. 4. Select the cells in the list (A2:B29 in this example). Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =MOD(SUBTOTAL(3,$A$1:$A2),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK 8. Filter the list, and the shading will alternate in the visible rows.

Create Coloured Shapes You can use conditional formatting and the Wingding font to create coloured shapes in a cell. In this example, coloured shapes will appear in cells C3:C7, depending on the value in the adjacent cell in column B. If the value is less than 10, a red circle will appear, if the value is greater than 30, a green square will appear. Otherwise, a yellow diamond will appear. 1. In cell C3 enter the formula: =IF(B3="","",IF(B3<10,"l",IF(B3>30,"n","t"))) 2. Copy the formula down to cell C7 3. Format cells C3:C7 with Wingding font, and yellow font color 4. Select cells C3:C7 5. Choose Format|Conditional Formatting 6. From the first dropdown, choose Formula Is 7. For the formula, use the Today function count the days: =$B3<10 8. Click the Format button, and select Red as the font colour, then click OK. 9. Click the Add button, and for Condition 2, choose Format|Conditional Formatting 10. From the first dropdown, choose Formula Is 11. For the formula, use the Today function count the days: =$B3>30 12. Click the Format button, and select Green as the font colour, then click OK. 13. Click OK 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Multiple Cells 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Conditional Formatting -- Examples


Hide Errors Hide Duplicate Values Highlight Duplicates in Column Highlight Items in a List Highlight Lottery Numbers Highlight Upcoming Expiry Dates Hide Cell Contents When Printing Shade Alternating Rows Shade Bands of Rows Shade Alternating Filtered Rows Create Coloured Shapes Hide Errors You can use conditional formatting to check for errors, and change the font colour to match the cell colour. In this example, if column B contains a zero, the #DIV/0! error is displayed in column C. 1. Select cells C2:C5 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter a formula that refers to the active cell in the selection: =ISERROR(C2) or, to hide only #N/A errors: =ISNA(C2) 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK download a zipped sample file

Hide Duplicate Values In a table, each row should have all data entered, to enable sorting and filtering. However, you can hide the duplicate values, to make the list easier to read. In this example, when the table is sorted by Region, the second (and subsequent) occurences of each region name will have white font colour. 1. 2. 3. 4. Select range A2:A5 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =A2=A1 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK Highlight Duplicates in Column Use conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK Highlight Items in a List Use conditional formatting to highlight items that are in a list on the worksheet.: 1. Create a list of items you want to highlight. If the items are on a different sheet than the conditional formatting, name the list. 2. Select range A2:A7 3. Choose Format|Conditional Formatting 4. From the first dropdown, choose Formula Is 5. For the formula, enter =COUNTIF($C$2:$C$4,A2) or, if the list is named, use the name in the formula: =COUNTIF(CodeList,A2) 6. Click the Format button. 7. Select a font colour for highlighting. 8. Click OK, click OK

Highlight Lottery Numbers You can highlight the ticket numbers that have been drawn in a lottery. In this example the ticket numbers are in cells B2:G4, and the drawn numbers are entered in cells B6:G6 1. 2. 3. 4. Select cells B2:G4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the CountIf function: =COUNTIF($B$6:$G$6,B2) 5. Click the Format button. 6. Select formatting options (green pattern, in this example), click OK 7. Click OK Highlight Upcoming Expiry Dates You can highlight payments that are due in the next thirty days. In this example, Due dates are entered in cells A2:A4. 1. 2. 3. 4. Select cells A2:A4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the Today function count the days: =AND(A2-TODAY()>=0,A2-TODAY()<=30) 5. Click the Format button. 6. Select formatting options (Bold, Blue font, in this example), click OK 7. Click OK Hide Cell Contents When Printing You can use conditional formatting to hide cells when printing. In this example, the contents of cells B2:F4 are changed to white font, if cell H1 contains an x. To print with the cell contents hidden, type an x in cell H1. To display the cell contents, delete the x in cell H1. 1. 2. 3. 4. 5. 6. Select cells B2:F4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =$H$1="x" Click the Format button. Select formatting options (white font and white pattern, in this example)

7. Click OK, click OK

Shade Alternating Rows You can use conditional formatting to shade alternating rows on the worksheet. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Bands of Rows You can use conditional formatting to shade bands of rows on the worksheet. In this example, 3 rows are shaded light grey, and 3 are left with no shading. In the MOD function, the total number of rows in the set of banded rows (6) is entered. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),6)<3 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Alternating Filtered Rows You can use conditional formatting to shade alternating rows in a filtered list. 1. 2. 3. 4. Select the cells in the list (A2:B29 in this example). Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =MOD(SUBTOTAL(3,$A$1:$A2),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK 8. Filter the list, and the shading will alternate in the visible rows.

Create Coloured Shapes You can use conditional formatting and the Wingding font to create coloured shapes in a cell. In this example, coloured shapes will appear in cells C3:C7, depending on the value in the adjacent cell in column B. If the value is less than 10, a red circle will appear, if the value is greater than 30, a green square will appear. Otherwise, a yellow diamond will appear. 1. In cell C3 enter the formula: =IF(B3="","",IF(B3<10,"l",IF(B3>30,"n","t"))) 2. Copy the formula down to cell C7 3. Format cells C3:C7 with Wingding font, and yellow font color 4. Select cells C3:C7 5. Choose Format|Conditional Formatting 6. From the first dropdown, choose Formula Is 7. For the formula, use the Today function count the days: =$B3<10 8. Click the Format button, and select Red as the font colour, then click OK. 9. Click the Add button, and for Condition 2, choose Format|Conditional Formatting 10. From the first dropdown, choose Formula Is 11. For the formula, use the Today function count the days: =$B3>30 12. Click the Format button, and select Green as the font colour, then click OK. 13. Click OK 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Multiple Cells 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Conditional Formatting -- Examples


Hide Errors Hide Duplicate Values Highlight Duplicates in Column Highlight Items in a List Highlight Lottery Numbers Highlight Upcoming Expiry Dates Hide Cell Contents When Printing Shade Alternating Rows Shade Bands of Rows Shade Alternating Filtered Rows Create Coloured Shapes Hide Errors You can use conditional formatting to check for errors, and change the font colour to match the cell colour. In this example, if column B contains a zero, the #DIV/0! error is displayed in column C. 1. Select cells C2:C5 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter a formula that refers to the active cell in the selection: =ISERROR(C2) or, to hide only #N/A errors: =ISNA(C2) 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK download a zipped sample file

Hide Duplicate Values In a table, each row should have all data entered, to enable sorting and filtering. However, you can hide the duplicate values, to make the list easier to read. In this example, when the table is sorted by Region, the second (and subsequent) occurences of each region name will have white font colour. 1. 2. 3. 4. Select range A2:A5 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =A2=A1 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK Highlight Duplicates in Column Use conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK Highlight Items in a List Use conditional formatting to highlight items that are in a list on the worksheet.: 1. Create a list of items you want to highlight. If the items are on a different sheet than the conditional formatting, name the list. 2. Select range A2:A7 3. Choose Format|Conditional Formatting 4. From the first dropdown, choose Formula Is 5. For the formula, enter =COUNTIF($C$2:$C$4,A2) or, if the list is named, use the name in the formula: =COUNTIF(CodeList,A2) 6. Click the Format button. 7. Select a font colour for highlighting. 8. Click OK, click OK

Highlight Lottery Numbers You can highlight the ticket numbers that have been drawn in a lottery. In this example the ticket numbers are in cells B2:G4, and the drawn numbers are entered in cells B6:G6 1. 2. 3. 4. Select cells B2:G4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the CountIf function: =COUNTIF($B$6:$G$6,B2) 5. Click the Format button. 6. Select formatting options (green pattern, in this example), click OK 7. Click OK Highlight Upcoming Expiry Dates You can highlight payments that are due in the next thirty days. In this example, Due dates are entered in cells A2:A4. 1. 2. 3. 4. Select cells A2:A4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the Today function count the days: =AND(A2-TODAY()>=0,A2-TODAY()<=30) 5. Click the Format button. 6. Select formatting options (Bold, Blue font, in this example), click OK 7. Click OK Hide Cell Contents When Printing You can use conditional formatting to hide cells when printing. In this example, the contents of cells B2:F4 are changed to white font, if cell H1 contains an x. To print with the cell contents hidden, type an x in cell H1. To display the cell contents, delete the x in cell H1. 1. 2. 3. 4. 5. 6. Select cells B2:F4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =$H$1="x" Click the Format button. Select formatting options (white font and white pattern, in this example)

7. Click OK, click OK

Shade Alternating Rows You can use conditional formatting to shade alternating rows on the worksheet. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Bands of Rows You can use conditional formatting to shade bands of rows on the worksheet. In this example, 3 rows are shaded light grey, and 3 are left with no shading. In the MOD function, the total number of rows in the set of banded rows (6) is entered. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),6)<3 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Alternating Filtered Rows You can use conditional formatting to shade alternating rows in a filtered list. 1. 2. 3. 4. Select the cells in the list (A2:B29 in this example). Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =MOD(SUBTOTAL(3,$A$1:$A2),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK 8. Filter the list, and the shading will alternate in the visible rows.

Create Coloured Shapes You can use conditional formatting and the Wingding font to create coloured shapes in a cell. In this example, coloured shapes will appear in cells C3:C7, depending on the value in the adjacent cell in column B. If the value is less than 10, a red circle will appear, if the value is greater than 30, a green square will appear. Otherwise, a yellow diamond will appear. 1. In cell C3 enter the formula: =IF(B3="","",IF(B3<10,"l",IF(B3>30,"n","t"))) 2. Copy the formula down to cell C7 3. Format cells C3:C7 with Wingding font, and yellow font color 4. Select cells C3:C7 5. Choose Format|Conditional Formatting 6. From the first dropdown, choose Formula Is 7. For the formula, use the Today function count the days: =$B3<10 8. Click the Format button, and select Red as the font colour, then click OK. 9. Click the Add button, and for Condition 2, choose Format|Conditional Formatting 10. From the first dropdown, choose Formula Is 11. For the formula, use the Today function count the days: =$B3>30 12. Click the Format button, and select Green as the font colour, then click OK. 13. Click OK 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Multiple Cells 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Conditional Formatting -- Examples


Hide Errors Hide Duplicate Values Highlight Duplicates in Column Highlight Items in a List Highlight Lottery Numbers Highlight Upcoming Expiry Dates Hide Cell Contents When Printing Shade Alternating Rows Shade Bands of Rows Shade Alternating Filtered Rows Create Coloured Shapes Hide Errors You can use conditional formatting to check for errors, and change the font colour to match the cell colour. In this example, if column B contains a zero, the #DIV/0! error is displayed in column C. 1. Select cells C2:C5 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter a formula that refers to the active cell in the selection: =ISERROR(C2) or, to hide only #N/A errors: =ISNA(C2) 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK download a zipped sample file

Hide Duplicate Values In a table, each row should have all data entered, to enable sorting and filtering. However, you can hide the duplicate values, to make the list easier to read. In this example, when the table is sorted by Region, the second (and subsequent) occurences of each region name will have white font colour. 1. 2. 3. 4. Select range A2:A5 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =A2=A1 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK Highlight Duplicates in Column Use conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK Highlight Items in a List Use conditional formatting to highlight items that are in a list on the worksheet.: 1. Create a list of items you want to highlight. If the items are on a different sheet than the conditional formatting, name the list. 2. Select range A2:A7 3. Choose Format|Conditional Formatting 4. From the first dropdown, choose Formula Is 5. For the formula, enter =COUNTIF($C$2:$C$4,A2) or, if the list is named, use the name in the formula: =COUNTIF(CodeList,A2) 6. Click the Format button. 7. Select a font colour for highlighting. 8. Click OK, click OK

Highlight Lottery Numbers You can highlight the ticket numbers that have been drawn in a lottery. In this example the ticket numbers are in cells B2:G4, and the drawn numbers are entered in cells B6:G6 1. 2. 3. 4. Select cells B2:G4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the CountIf function: =COUNTIF($B$6:$G$6,B2) 5. Click the Format button. 6. Select formatting options (green pattern, in this example), click OK 7. Click OK Highlight Upcoming Expiry Dates You can highlight payments that are due in the next thirty days. In this example, Due dates are entered in cells A2:A4. 1. 2. 3. 4. Select cells A2:A4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the Today function count the days: =AND(A2-TODAY()>=0,A2-TODAY()<=30) 5. Click the Format button. 6. Select formatting options (Bold, Blue font, in this example), click OK 7. Click OK Hide Cell Contents When Printing You can use conditional formatting to hide cells when printing. In this example, the contents of cells B2:F4 are changed to white font, if cell H1 contains an x. To print with the cell contents hidden, type an x in cell H1. To display the cell contents, delete the x in cell H1. 1. 2. 3. 4. 5. 6. Select cells B2:F4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =$H$1="x" Click the Format button. Select formatting options (white font and white pattern, in this example)

7. Click OK, click OK

Shade Alternating Rows You can use conditional formatting to shade alternating rows on the worksheet. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Bands of Rows You can use conditional formatting to shade bands of rows on the worksheet. In this example, 3 rows are shaded light grey, and 3 are left with no shading. In the MOD function, the total number of rows in the set of banded rows (6) is entered. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),6)<3 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Alternating Filtered Rows You can use conditional formatting to shade alternating rows in a filtered list. 1. 2. 3. 4. Select the cells in the list (A2:B29 in this example). Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =MOD(SUBTOTAL(3,$A$1:$A2),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK 8. Filter the list, and the shading will alternate in the visible rows.

Create Coloured Shapes You can use conditional formatting and the Wingding font to create coloured shapes in a cell. In this example, coloured shapes will appear in cells C3:C7, depending on the value in the adjacent cell in column B. If the value is less than 10, a red circle will appear, if the value is greater than 30, a green square will appear. Otherwise, a yellow diamond will appear. 1. In cell C3 enter the formula: =IF(B3="","",IF(B3<10,"l",IF(B3>30,"n","t"))) 2. Copy the formula down to cell C7 3. Format cells C3:C7 with Wingding font, and yellow font color 4. Select cells C3:C7 5. Choose Format|Conditional Formatting 6. From the first dropdown, choose Formula Is 7. For the formula, use the Today function count the days: =$B3<10 8. Click the Format button, and select Red as the font colour, then click OK. 9. Click the Add button, and for Condition 2, choose Format|Conditional Formatting 10. From the first dropdown, choose Formula Is 11. For the formula, use the Today function count the days: =$B3>30 12. Click the Format button, and select Green as the font colour, then click OK. 13. Click OK 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Multiple Cells 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Conditional Formatting -- Examples


Hide Errors Hide Duplicate Values Highlight Duplicates in Column Highlight Items in a List Highlight Lottery Numbers Highlight Upcoming Expiry Dates Hide Cell Contents When Printing Shade Alternating Rows Shade Bands of Rows Shade Alternating Filtered Rows Create Coloured Shapes Hide Errors You can use conditional formatting to check for errors, and change the font colour to match the cell colour. In this example, if column B contains a zero, the #DIV/0! error is displayed in column C. 1. Select cells C2:C5 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter a formula that refers to the active cell in the selection: =ISERROR(C2) or, to hide only #N/A errors: =ISNA(C2) 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK download a zipped sample file

Hide Duplicate Values In a table, each row should have all data entered, to enable sorting and filtering. However, you can hide the duplicate values, to make the list easier to read. In this example, when the table is sorted by Region, the second (and subsequent) occurences of each region name will have white font colour. 1. 2. 3. 4. Select range A2:A5 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =A2=A1 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK Highlight Duplicates in Column Use conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK Highlight Items in a List Use conditional formatting to highlight items that are in a list on the worksheet.: 1. Create a list of items you want to highlight. If the items are on a different sheet than the conditional formatting, name the list. 2. Select range A2:A7 3. Choose Format|Conditional Formatting 4. From the first dropdown, choose Formula Is 5. For the formula, enter =COUNTIF($C$2:$C$4,A2) or, if the list is named, use the name in the formula: =COUNTIF(CodeList,A2) 6. Click the Format button. 7. Select a font colour for highlighting. 8. Click OK, click OK

Highlight Lottery Numbers You can highlight the ticket numbers that have been drawn in a lottery. In this example the ticket numbers are in cells B2:G4, and the drawn numbers are entered in cells B6:G6 1. 2. 3. 4. Select cells B2:G4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the CountIf function: =COUNTIF($B$6:$G$6,B2) 5. Click the Format button. 6. Select formatting options (green pattern, in this example), click OK 7. Click OK Highlight Upcoming Expiry Dates You can highlight payments that are due in the next thirty days. In this example, Due dates are entered in cells A2:A4. 1. 2. 3. 4. Select cells A2:A4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the Today function count the days: =AND(A2-TODAY()>=0,A2-TODAY()<=30) 5. Click the Format button. 6. Select formatting options (Bold, Blue font, in this example), click OK 7. Click OK Hide Cell Contents When Printing You can use conditional formatting to hide cells when printing. In this example, the contents of cells B2:F4 are changed to white font, if cell H1 contains an x. To print with the cell contents hidden, type an x in cell H1. To display the cell contents, delete the x in cell H1. 1. 2. 3. 4. 5. 6. Select cells B2:F4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =$H$1="x" Click the Format button. Select formatting options (white font and white pattern, in this example)

7. Click OK, click OK

Shade Alternating Rows You can use conditional formatting to shade alternating rows on the worksheet. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Bands of Rows You can use conditional formatting to shade bands of rows on the worksheet. In this example, 3 rows are shaded light grey, and 3 are left with no shading. In the MOD function, the total number of rows in the set of banded rows (6) is entered. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),6)<3 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Alternating Filtered Rows You can use conditional formatting to shade alternating rows in a filtered list. 1. 2. 3. 4. Select the cells in the list (A2:B29 in this example). Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =MOD(SUBTOTAL(3,$A$1:$A2),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK 8. Filter the list, and the shading will alternate in the visible rows.

Create Coloured Shapes You can use conditional formatting and the Wingding font to create coloured shapes in a cell. In this example, coloured shapes will appear in cells C3:C7, depending on the value in the adjacent cell in column B. If the value is less than 10, a red circle will appear, if the value is greater than 30, a green square will appear. Otherwise, a yellow diamond will appear. 1. In cell C3 enter the formula: =IF(B3="","",IF(B3<10,"l",IF(B3>30,"n","t"))) 2. Copy the formula down to cell C7 3. Format cells C3:C7 with Wingding font, and yellow font color 4. Select cells C3:C7 5. Choose Format|Conditional Formatting 6. From the first dropdown, choose Formula Is 7. For the formula, use the Today function count the days: =$B3<10 8. Click the Format button, and select Red as the font colour, then click OK. 9. Click the Add button, and for Condition 2, choose Format|Conditional Formatting 10. From the first dropdown, choose Formula Is 11. For the formula, use the Today function count the days: =$B3>30 12. Click the Format button, and select Green as the font colour, then click OK. 13. Click OK 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Multiple Cells 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Conditional Formatting -- Examples


Hide Errors Hide Duplicate Values Highlight Duplicates in Column Highlight Items in a List Highlight Lottery Numbers Highlight Upcoming Expiry Dates Hide Cell Contents When Printing Shade Alternating Rows Shade Bands of Rows Shade Alternating Filtered Rows Create Coloured Shapes Hide Errors You can use conditional formatting to check for errors, and change the font colour to match the cell colour. In this example, if column B contains a zero, the #DIV/0! error is displayed in column C. 1. Select cells C2:C5 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter a formula that refers to the active cell in the selection: =ISERROR(C2) or, to hide only #N/A errors: =ISNA(C2) 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK download a zipped sample file

Hide Duplicate Values In a table, each row should have all data entered, to enable sorting and filtering. However, you can hide the duplicate values, to make the list easier to read. In this example, when the table is sorted by Region, the second (and subsequent) occurences of each region name will have white font colour. 1. 2. 3. 4. Select range A2:A5 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =A2=A1 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK Highlight Duplicates in Column Use conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK Highlight Items in a List Use conditional formatting to highlight items that are in a list on the worksheet.: 1. Create a list of items you want to highlight. If the items are on a different sheet than the conditional formatting, name the list. 2. Select range A2:A7 3. Choose Format|Conditional Formatting 4. From the first dropdown, choose Formula Is 5. For the formula, enter =COUNTIF($C$2:$C$4,A2) or, if the list is named, use the name in the formula: =COUNTIF(CodeList,A2) 6. Click the Format button. 7. Select a font colour for highlighting. 8. Click OK, click OK

Highlight Lottery Numbers You can highlight the ticket numbers that have been drawn in a lottery. In this example the ticket numbers are in cells B2:G4, and the drawn numbers are entered in cells B6:G6 1. 2. 3. 4. Select cells B2:G4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the CountIf function: =COUNTIF($B$6:$G$6,B2) 5. Click the Format button. 6. Select formatting options (green pattern, in this example), click OK 7. Click OK Highlight Upcoming Expiry Dates You can highlight payments that are due in the next thirty days. In this example, Due dates are entered in cells A2:A4. 1. 2. 3. 4. Select cells A2:A4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the Today function count the days: =AND(A2-TODAY()>=0,A2-TODAY()<=30) 5. Click the Format button. 6. Select formatting options (Bold, Blue font, in this example), click OK 7. Click OK Hide Cell Contents When Printing You can use conditional formatting to hide cells when printing. In this example, the contents of cells B2:F4 are changed to white font, if cell H1 contains an x. To print with the cell contents hidden, type an x in cell H1. To display the cell contents, delete the x in cell H1. 1. 2. 3. 4. 5. 6. Select cells B2:F4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =$H$1="x" Click the Format button. Select formatting options (white font and white pattern, in this example)

7. Click OK, click OK

Shade Alternating Rows You can use conditional formatting to shade alternating rows on the worksheet. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Bands of Rows You can use conditional formatting to shade bands of rows on the worksheet. In this example, 3 rows are shaded light grey, and 3 are left with no shading. In the MOD function, the total number of rows in the set of banded rows (6) is entered. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),6)<3 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Alternating Filtered Rows You can use conditional formatting to shade alternating rows in a filtered list. 1. 2. 3. 4. Select the cells in the list (A2:B29 in this example). Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =MOD(SUBTOTAL(3,$A$1:$A2),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK 8. Filter the list, and the shading will alternate in the visible rows.

Create Coloured Shapes You can use conditional formatting and the Wingding font to create coloured shapes in a cell. In this example, coloured shapes will appear in cells C3:C7, depending on the value in the adjacent cell in column B. If the value is less than 10, a red circle will appear, if the value is greater than 30, a green square will appear. Otherwise, a yellow diamond will appear. 1. In cell C3 enter the formula: =IF(B3="","",IF(B3<10,"l",IF(B3>30,"n","t"))) 2. Copy the formula down to cell C7 3. Format cells C3:C7 with Wingding font, and yellow font color 4. Select cells C3:C7 5. Choose Format|Conditional Formatting 6. From the first dropdown, choose Formula Is 7. For the formula, use the Today function count the days: =$B3<10 8. Click the Format button, and select Red as the font colour, then click OK. 9. Click the Add button, and for Condition 2, choose Format|Conditional Formatting 10. From the first dropdown, choose Formula Is 11. For the formula, use the Today function count the days: =$B3>30 12. Click the Format button, and select Green as the font colour, then click OK. 13. Click OK 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Multiple Cells 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Conditional Formatting -- Examples


Hide Errors Hide Duplicate Values Highlight Duplicates in Column Highlight Items in a List Highlight Lottery Numbers Highlight Upcoming Expiry Dates Hide Cell Contents When Printing Shade Alternating Rows Shade Bands of Rows Shade Alternating Filtered Rows Create Coloured Shapes Hide Errors You can use conditional formatting to check for errors, and change the font colour to match the cell colour. In this example, if column B contains a zero, the #DIV/0! error is displayed in column C. 1. Select cells C2:C5 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter a formula that refers to the active cell in the selection: =ISERROR(C2) or, to hide only #N/A errors: =ISNA(C2) 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK download a zipped sample file

Hide Duplicate Values In a table, each row should have all data entered, to enable sorting and filtering. However, you can hide the duplicate values, to make the list easier to read. In this example, when the table is sorted by Region, the second (and subsequent) occurences of each region name will have white font colour. 1. 2. 3. 4. Select range A2:A5 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =A2=A1 5. Click the Format button. 6. Select a font colour to match the cell colour. 7. Click OK, click OK Highlight Duplicates in Column Use conditional formatting to highlight duplicate entries in a column: 1. Select range A2:A11 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =COUNTIF($A$2:$A$11,A2)>1 5. Click the Format button. 6. Select a font colour for highlighting. 7. Click OK, click OK Highlight Items in a List Use conditional formatting to highlight items that are in a list on the worksheet.: 1. Create a list of items you want to highlight. If the items are on a different sheet than the conditional formatting, name the list. 2. Select range A2:A7 3. Choose Format|Conditional Formatting 4. From the first dropdown, choose Formula Is 5. For the formula, enter =COUNTIF($C$2:$C$4,A2) or, if the list is named, use the name in the formula: =COUNTIF(CodeList,A2) 6. Click the Format button. 7. Select a font colour for highlighting. 8. Click OK, click OK

Highlight Lottery Numbers You can highlight the ticket numbers that have been drawn in a lottery. In this example the ticket numbers are in cells B2:G4, and the drawn numbers are entered in cells B6:G6 1. 2. 3. 4. Select cells B2:G4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the CountIf function: =COUNTIF($B$6:$G$6,B2) 5. Click the Format button. 6. Select formatting options (green pattern, in this example), click OK 7. Click OK Highlight Upcoming Expiry Dates You can highlight payments that are due in the next thirty days. In this example, Due dates are entered in cells A2:A4. 1. 2. 3. 4. Select cells A2:A4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, use the Today function count the days: =AND(A2-TODAY()>=0,A2-TODAY()<=30) 5. Click the Format button. 6. Select formatting options (Bold, Blue font, in this example), click OK 7. Click OK Hide Cell Contents When Printing You can use conditional formatting to hide cells when printing. In this example, the contents of cells B2:F4 are changed to white font, if cell H1 contains an x. To print with the cell contents hidden, type an x in cell H1. To display the cell contents, delete the x in cell H1. 1. 2. 3. 4. 5. 6. Select cells B2:F4 Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =$H$1="x" Click the Format button. Select formatting options (white font and white pattern, in this example)

7. Click OK, click OK

Shade Alternating Rows You can use conditional formatting to shade alternating rows on the worksheet. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Bands of Rows You can use conditional formatting to shade bands of rows on the worksheet. In this example, 3 rows are shaded light grey, and 3 are left with no shading. In the MOD function, the total number of rows in the set of banded rows (6) is entered. 1. Click the Select All button, above the Row 1 button, to select all the cells on the worksheet. 2. Choose Format|Conditional Formatting 3. From the first dropdown, choose Formula Is 4. For the formula, enter =MOD(ROW(),6)<3 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK Shade Alternating Filtered Rows You can use conditional formatting to shade alternating rows in a filtered list. 1. 2. 3. 4. Select the cells in the list (A2:B29 in this example). Choose Format|Conditional Formatting From the first dropdown, choose Formula Is For the formula, enter =MOD(SUBTOTAL(3,$A$1:$A2),2) 5. Click the Format button. 6. On the Patterns tab, select a colour for shading 7. Click OK, click OK 8. Filter the list, and the shading will alternate in the visible rows.

Create Coloured Shapes You can use conditional formatting and the Wingding font to create coloured shapes in a cell. In this example, coloured shapes will appear in cells C3:C7, depending on the value in the adjacent cell in column B. If the value is less than 10, a red circle will appear, if the value is greater than 30, a green square will appear. Otherwise, a yellow diamond will appear. 1. In cell C3 enter the formula: =IF(B3="","",IF(B3<10,"l",IF(B3>30,"n","t"))) 2. Copy the formula down to cell C7 3. Format cells C3:C7 with Wingding font, and yellow font color 4. Select cells C3:C7 5. Choose Format|Conditional Formatting 6. From the first dropdown, choose Formula Is 7. For the formula, use the Today function count the days: =$B3<10 8. Click the Format button, and select Red as the font colour, then click OK. 9. Click the Add button, and for Condition 2, choose Format|Conditional Formatting 10. From the first dropdown, choose Formula Is 11. For the formula, use the Today function count the days: =$B3>30 12. Click the Format button, and select Green as the font colour, then click OK. 13. Click OK 1. Conditional Formatting -- Introduction 2. Conditional Formatting -- Multiple Cells 3. Conditional Formatting -- Examples 4. Conditional Formatting -- Documentation

Excel -- Worksheet Functions -- Count Cells


Count Cells with Numbers-- COUNT Count Cells with Data-- COUNTA Count Blank Cells -- COUNTBLANK Count cells that match criteria -- COUNTIF - Match criterion exactly - Match criterion in a string - Match criterion using operator - Match criteria in a range Count cells that match multiple criteria -- SUMPRODUCT Count the Numbers in a Filtered List -- SUBTOTAL Count Specific Items in a Filtered List Count Visible Items in a Filtered List Count Cells with Numbers -- COUNT The COUNT function will count cells that contain numbers. Its syntax is: =COUNT(value1, value2,...value30). The arguments (e.g. value1) can be cell references, or values typed into the formula. The following example uses one argument -- a reference to cells A1:A5. 1. Enter the sample data on your worksheet 2. In cell A7, enter a COUNT formula, to count the numbers in column A: =COUNT(A1:A5) 3. Press the Enter key, to complete the formula. 4. The result will be 3, the number of cells that contain numbers. Cell A1 isn't counted, because it contains text. Note: Since dates are stored as numbers, COUNT will include any cells that contain dates. Download zipped sample workbook

=COUNT(A1:A5)

Count Cells with Data -- COUNTA The COUNTA function will count cells that are not empty. Its syntax is: =COUNTA(value1, value2,...value30). The arguments (e.g. value1) can be cell references, or values typed into the formula. The following example uses one argument -- a reference to cells A1:A5. 1. Enter the sample data on your worksheet 2. In cell A7, enter a COUNTA formula, to count the numbers in column A: =COUNTA(A1:A5) 3. Press the Enter key, to complete the formula. 4. The result will be 4, the number of cells that contain data. Note: COUNTA will count cells with formulas including those that look empty, because they evaluate to "", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but then were converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank" converted cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys." Count Blank Cells -- COUNTBLANK The COUNTBLANK function will count cells that are empty. Its syntax is: =COUNTBLANK(range). The following example uses a reference to cells A1:A5. 1. Enter the sample data on your worksheet 2. In cell A7, enter a COUNTBLANK formula, to count the numbers in column A: =COUNTBLANK(A1:A5) 3. Press the Enter key, to complete the formula. 4. The result will be 1, the number of empty cells. Note: COUNTBLANK will count cells with formulas including those that look empty, because they evaluate to "", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but then were converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank" converted cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys." =COUNTA(A1:A5)

=COUNTBLANK(A1:A5)

Count cells that match criteria -- COUNTIF Match criterion exactly You can count cells that meet a specific criterion. In this example only the Pen orders will be counted. 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: COUNTIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes: "Pen" Note: upper and lower case are treated equally 7. Type a closing bracket The completed formula is: =COUNTIF(A1:A10,"Pen") 8. Press the Enter key to complete the entry 9. The result will be 4, the number of cells that contain "Pen"

Match criterion in a string You can count cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be counted, because they contain the string "pen". 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: COUNTIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters: "*Pen*" Note: upper and lower case are treated equally 7. Type a closing bracket The completed formula is: =COUNTIF(A1:A10,"*Pen*") 8. Press the Enter key to complete the entry 9. The result will be 6, the number of cells that contain the string, "Pen" Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 7 above could be changed to: =COUNTIF(A1:A10,"*" & B12 & "*") if cell B12 contained the text pen.

Criterion and operator You can use an operator with a criterion. In this example only the rows where the quantity is greater than or equal to ten will be counted. 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: COUNTIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells B1:B10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for rows where the quantity is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes: ">=10" Note: Even though this is a numerical criterion, it must enclosed in double quote marks. 7. Type a closing bracket 8. The completed formula is: =COUNTIF(B1:B10,">=10") 9. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8 above could be changed to: =COUNTIF(B1:B10,">=" & B12) if cell B12 contained the number 10. Or, you could use a function as part of the criterion. For example: =COUNTIF(A1:A10,"<"&TODAY())

Match criteria in a range You can combine COUNTIF formulas, to count rows that are within a range of values. In this example, the formula will count rows where the quantity is between 5 and 10 (inclusive). 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type a formula to count rows greater than or equal to 5: =COUNTIF(B1:B10,">=5") 3. Type a minus sign 4. Type a formula to count rows greater than 10: COUNTIF(B1:B10,">10") 5. The completed formula is: =COUNTIF(B1:B10,">=5")COUNTIF(B1:B10,">10") 6. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8 above could be changed to: =COUNTIF(B1:B10,">=" & B12) COUNTIF(B1:B10,">" & C12) if cell B12 contained the number 5 and cell C12 contained the number 10.

Count cells that match multiple criteria -SUMPRODUCT Match multiple criteria You can count rows that meet two or more criteria. In this example only the rows where the item is "Pen" and the quantity is greater than or equal to ten will be counted. 1. Select the cell in which you want to see the total 2. Type an equal sign (=) to start the formula 3. Type: SUMPRODUCT(--( 4. Select the cells that contain the values to check for the first criterion. In this example, cells A2:A10 will be checked 5. Type the first criterion: ="Pen" Note: Because this is a text criterion, it is enclosed in double quote marks. 6. Type ),--( 7. Select the cells that contain the values to check for the second

criterion. In this example, cells B2:B10 will be checked 8. Type the second criterion: >=10 Note: Because this is a numerical criterion, it isn't enclosed in double quote marks. 9. Finish with closing brackets: )) 10. The completed formula is shown at right. 11. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell, as shown in the second formula at right

Use typed criteria: =SUMPRODUCT(--(A2:A10="Pen"),--(B2:B10>=10)) or cell references: =SUMPRODUCT(--(A2:A10=D2),--(B2:B10>=E2))

Count Rows in a Filtered List -- SUBTOTAL After you filter the rows in a list, you can use the SUBTOTAL function to count the visible rows. 1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics 2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders. 3. Select the cell immediately below the column you want to sum. 4. Click the AutoSum button on the Excel's Standard toolbar. o If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button. 5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column o The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. The default is 9, which tells Excel to SUM the numbers. o Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list. 6. To Count all the non-empty cells in column D, use a 3 as the first argument: =SUBTOTAL(3,D2:D10) 7. Press the Enter key to complete the formula entry. Note: In Excel 2003, you can use the formula:

=SUBTOTAL(3,D2:D10)

=SUBTOTAL(103,D2:D10) Count Visible Items in a Filtered List Laurent Longre created a formula that lets you work with visible rows after a filter. For information see, Power Formula Technique in this article at John Walkenbach's web site: http://j-walk.com/ss/excel/eee/eee001.txt Incorporating that technique, SUMPRODUCT can be used to count visible items in a filtered table. In the following example, column D has been filtered for amounts greater than 100. The following formula will count the number of visible rows that contain "Pen" in column A. 1. From the dropdown list in cell D1, select Custom. 2. Filter for rows greater than 100. 3. In cell A12, type: Pen 4. In cell B12, enter the following formula: =SUMPRODUCT(SUBTOTAL(3,OFFSET(A1:A10,ROW(A1:A10) -MIN(ROW(A1:A10)),,1)), --(A1:A10=A12)) 5. Press the Enter key to complete the formula entry. Download zipped sample workbook Worksheet Functions -- Sum Cells Worksheet Functions -- VLOOKUP Worksheet Functions -- INDEX / MATCH Worksheet Functions -- Count Cells Worksheet Functions -- INDIRECT

Excel -- Data Entry Tips


Enter Data Quickly -- Keyboard Enter Data Quickly -- Mouse Enter Data in a List Enter Data Quickly -- Keyboard

Use Shortcut Keys


Enter the current Date Enter the current Time Copy Value from cell above Copy Formula (exact) from cell above Copy Formula (relational reference) from cell above Ctrl + ; Ctrl + Shift + ; Ctrl + Shift + ' Ctrl + ' Ctrl + D

Enter Data in Multiple Cells 1. Select all the cells in which you want to enter the same value or formula 2. Type the value or formula in the active cell 3. Hold the Ctrl key and press Enter

Ctrl + Enter

Copy Data to Adjacent Cells

1. Select the range, starting with the cell that contains the data to be copied 2. Use a shortcut key to fill right or down: o Fill Right -- Ctrl + R
o

Fill Down -- Ctrl + D

Enter Data Quickly -- Mouse

Copy Data to Adjacent Cells

1. Select the cell that contains the data to be copied 2. Point to the Fill Handle -- the black square at the lower right of the selection 3. When the pointer changes to a black plus sign, press the Left mouse button, and drag left, right, up or down, across one or more cells. 4. When finished, release the mouse button. Copy to Adjacent Cells -- with options 1. Select the cell that contains the data to be copied 2. Point to the Fill Handle -- the black square at the lower right of the selection 3. When the pointer changes to a black plus sign, press the Right mouse button, and drag left, right, up or down, across one or more cells. 4. When finished, release the mouse button. 5. Select one of the options from the shortcut menu Enter Data in a List Use Excel's built-in Data Form to make it easier to enter data in a list. It will display a maximum of 32 fields. 1. Select a cell in the list. 2. Choose Data|Form 3. Click the New button, and enter the new record Note: Fields which contain a formula, such as Total in the Data form shown here, will not have a text box. The formula will be entered and calculated automatically. For a data form with additional features, you can try John Walkenbach's Enhanced Data Form. It's free, and allows unlimited fields. 1. Data Entry -- Tips

2. Data Entry -- Fill Blank Cells 3. Data Entry -- Convert Text to Numbers 4. Data Entry -- Increase Numbers With Paste Special

Excel -- Data Entry -- Fill Blank Cells


Fill Blank Cells Fill Blank Cells Programmatically Fill Blank Cells Some worksheets contain cells that have been left blank, in order to make the headings and subheadings easier to read. However, if you want to sort or filter the list, you need to fill in the blanks, by copying the value from the first filled cell above the blank. The following technique makes it easy to fill in the blanks. Watch the Video View the steps described below, in a short video clip.

Start by selecting the empty cells:


1. Select the cells in the column, starting in the row below the column heading. 2. Choose Edit | Go To 3. Click the Special button 4. Select Blanks, click OK

Enter the formula to copy the value:


1. Type an equal sign 2. Press the up arrow on the keyboard -- this will enter a reference to the cell above -- cell A2 in this example 3. Hold the Ctrl key and press Enter -- this enters the formula in all selected cells

Change the formulas to values:


In order to sort or filter the data, the formulas must be changed to values. 1. Select the entire column 2. Choose Edit | Copy 3. With the column still selected, choose Edit | Paste Special 4. Select Values, click OK Note: Do this carefully if there are other cells in the range which contain formulas. Watch the Video View the steps described above, in a short video clip.

Fill Blank Cells Programmatically If you frequently have to fill blank cells, you may prefer to use a macro. The following code will fill blank cells in the active column:
Sub FillColBlanks() 'by Dave Peterson 2004-01-06 'fill blank cells in column with value above Dim wks As Worksheet Dim rng As Range Dim LastRow As Long Dim col As Long Set wks = ActiveSheet With wks col = activecell.column 'or 'col = .range("b1").column Set rng = .UsedRange 'try to reset the lastcell LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row Set rng = Nothing On Error Resume Next Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _ .Cells.SpecialCells(xlCellTypeBlanks ) On Error GoTo 0 If rng Is Nothing Then MsgBox "No blanks found" Exit Sub Else rng.FormulaR1C1 = "=R[-1]C" End If 'replace formulas with values With .Cells(1, col).EntireColumn .Value = .Value End With End With End Sub

1. Data Entry -- Tips 2. Data Entry -- Fill Blank Cells 3. Data Entry -- Convert Text to Numbers 4. Data Entry -- Increase Numbers With Paste Special

Excel -- Data Entry -- Convert Text to Numbers


Convert with Paste Special Convert Dates with Replace All Convert with Text to Columns Convert Trailing Minus Signs Convert Trailing Minus Signs Programmatically Paste as CSV Convert Programmatically

If you copy data from another program, such as Microsoft Access, or from a text file, Excel may treat the numbers as text.* Calculations that use these numbers will be incorrect, as in the SUM shown above. There are several methods that you can use to convert the text "numbers" to real numbers. Convert with Paste Special 1. 2. 3. 4. 5. 6. 7. Select a blank cell Choose Edit>Copy Select the cells that contain the numbers Choose Edit>Paste Special Select Add Click OK To apply number formatting, choose Format>Cells 8. On the Number tab, select the appropriate format, then click OK. Watch the Video View the steps described above, in a short video

clip.

Convert Dates with Replace All If dates are formatted with slashes, such as 5/5/04, you can convert them to real dates by replacing the slashes. 1. 2. 3. 4. 5. 6. Select the cells that contain the dates Choose Edit>Replace For Find what, type a forward slash: / For Replace with, type a forward slash: / Click Replace All To apply date formatting, choose Format>Cells 7. On the Number tab, select a date format, then click OK. Convert with Text to Columns 1. Select the cells that contain the numbers 2. Choose Data>Text to Columns 3. Click Finish

Convert Trailing Minus Signs In Excel 2002, and later versions, imported numbers with trailing minus signs can be easily converted to negative numbers. 1. Select the cells that contain the numbers 2. Choose Data>Text to Columns 3. To view the Trailing Minus setting, click Next, click Next 4. In Step 3, click the Advanced button 5. Check the box for 'Trailing minus for negative numbers', click OK 6. Click Finish Note: If 'Trailing minus for negative numbers' is checked, you can click Finish in Step 1 of the Text to Columns wizard.

Convert Trailing Minus Signs Programmatically In all versions of Excel, you can use the following macro to convert numbers with trailing minus signs.
Sub TrailingMinus() ' = = = = = = = = = = = = = = = = ' Use of CDbl suggested by Peter Surcouf ' Program by Dana DeLouis, dana2@msn.com ' modified by Tom Ogilvy ' = = = = = = = = = = = = = = = = Dim rng As Range Dim bigrng As Range On Error Resume Next Set bigrng = Cells _ .SpecialCells(xlConstants, xlTextValues).Cells If bigrng Is Nothing Then Exit Sub For Each rng In bigrng.Cells If IsNumeric(rng) Then rng = CDbl(rng) End If Next End Sub

Paste as CSV To prevent copied numbers from being pasted as text, you may be able to paste the data as CSV. 1. 2. 3. 4. 5. Copy the data in the other program Switch to Excel Select the cell where the paste will start Choose Edit>Paste Special Select CSV, click OK

Convert Programmatically If you frequently convert text to numbers, you can use a macro. Add a button to an existing toolbar, and attach the macro to that button. Then, select the cells, and click the toolbar button.
Sub ConvertToNumbers() Cells.SpecialCells(xlCellTypeLastCell) _ .Offset(1, 1).Copy Selection.PasteSpecial Paste:=xlPasteValues, _ Operation:=xlPasteSpecialOperationAdd With Selection .VerticalAlignment = xlTop .WrapText = False End With Selection.EntireColumn.AutoFit End Sub

Excel -- Data Entry -- Increase Numbers With Paste Special


Add the Same Amount to Selected Numbers Increase Selected Numbers by a Percentage View the steps described below, in a short video clip. Excel 2007 video Thanks to T. Valko for suggesting this page! Add the Same Amount to Selected Numbers You may want to increase all the numbers in a range by a set amount. For example, in this price list, all the prices should be increased by $1.50. The following technique makes it easy to increase the prices, all at once. 1. In a blank cell, enter the amount of the increase. In this example, 1.50 was entered in cell D2 2. Copy the cell which contains the increase amount. 3. Select the cells which contain the amounts that you want to increase. Here, cells B2:B5 are selected. 4. On the menu bar, click Edit | Paste Special 5. Click Values, and click Add, then click OK. 6. Each of the selected numbers is automatically increased by $1.50

Watch the Video View the steps described above, in a short video clip. Excel 2007 video

Increase Selected Numbers by a Percentage You may want to increase all the numbers in a range by a set percentage. For example, in this price list, all the prices should be increased by 5%. The following technique makes it easy to increase the prices, all at once. 1. In a blank cell, enter the amount of the increase. In this example, 1.05 was entered in cell D8 2. Copy the cell which contains the increase amount. 3. Select the cells which contain the amounts that you want to increase. Here, cells B8:B11 are selected. 4. On the menu bar, click Edit | Paste Special 5. Click Values, and click Multiply, then click OK. 6. Each of the selected numbers is automatically increased by 5%

Watch the Video View the steps described above, in a short video clip. Excel 2007 video 1. Data Entry -- Tips 2. Data Entry -- Fill Blank Cells 3. Data Entry -- Convert Text to Numbers 4. Data Entry -- Increase Numbers With Paste Special

Excel -- Data Validation -- Introduction

Download the zipped sample workbook

What is Data Validation? Provide a Drop-down List of Options o Create a List of Items o Name the List Range

o o o o

Apply the Data Validation Using a Delimited List Allow Entries that are not in the List Protect the List

To view the steps in a short video, click here What is Data Validation? Data validation is a tool that helps you control the kind of information that is entered in your worksheet. With data validation, you can: --provide users with a list of choices --restrict entries to a specific type or size --create custom settings Note: Data validation is not foolproof. It can be circumvented Data validation list by pasting data into the cell, or by choosing Edit|Clear| ClearAll Provide a Drop-down List of Options Use Data Validation to create a dropdown list of options in a cell. List items can be typed in a row or column on a worksheet, or typed directly into the Data Validation dialog box. 1. Create a List of Items If the list of options is more than a couple of items, it will be easier to maintain if you type the list on a worksheet. The list can be entered on the sheet that will contain the dropdown lists, or on a different sheet. In this example, the list will be stored on a sheet named Lists. a. In single row or column, type the entries you want to see in the drop-down list. (Note: The list must be in a single block of cells -- e.g. you can use A2:A6, but not A2, A4, A6, A8.) 2. Name the List Range If you type the items on a worksheet, and name the range, you can refer to the list from any worksheet in the same workbook. 1. Select the cells in the list. 2. Click in the Name box, to the left of the formula bar 3. Type a one-word name for the list, e.g. FruitList. 4. Press the Enter key.

Note: To create a named list that automatically expands to include new items, use a dynamic range.

3. Apply the Data Validation a. Select the cells in which you want to apply data validation b. From the Data menu, choose Validation. c. From the Allow drop-down list, choose List

d. In the Source box, type an equal sign and the list name, for example: =FruitList e. Click OK.

Tip: To select a range name, instead of typing it: 1. In the Data Validation dialog box, under Allow, select List 2. Click in the Source box, and on the keyboard, press the F3 key 3. From the Paste Name list, select a named range, and click OK. 4. Click OK, to close the Data Validation dialog box. To view the steps in a short video, click here 4. Using a Delimited List Instead of referring to a list of items on the worksheet, you can type the list in the Source box, separated by commas. For example: Yes,No,Maybe Note: This method of Data Validation is case sensitive -- if a user types YES, an error alert will be displayed. 5. Allow Entries that are not in the List To allow users to type items that are not in the list., turn off the Error Alert.

6. Protect the List To protect the list from accidental damage, if you have entered it on a different worksheet, you can hide that sheet. 1. Select the sheet that contains the list 2. Choose Format | Sheet | Hide Download the zipped sample workbook 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips

9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Combo box


Create a Data Validation Dropdown List Add the Combo box Open the Properties Window Change the Combo box Properties Exit Design Mode Add the Code Test the Code You can use Data Validation to create a dropdown list of options in a cell. However, the list font can't be changed, nor can the number of visible rows, which has a maximum of eight. Also, Data Validation doesn't have an AutoComplete feature, which finds matching items in the list as you start to type. To overcome these limitations, you can add a combo box to your worksheet, and use programming to make it appear in cells that contain a data validation list. Double-click on a cell that contains a data validation list, and the combo box appears. The combo box's font size can be set, more than 8 rows can be displayed, and autocomplete can be enabled. Note: If the worksheet is protected, allow users to Edit

Download the zipped sample file

Objects, and they will be able to use the combobox.

Create a Data Validation Dropdown List On Sheet1, type the lists that will be used in the data validation dropdowns: Tip: Use the AutoFill feature to create the lists 1. In cells K2:K8 type a list of weekdays 2. In cells M2:M13 type a list of months The next step is to create the data validation dropdown lists. There are detailed instructions here: Data Validation -- Introduction

Cells C2:C12 have data validation lists with the source K2:K8. When a cell in this range is selected, a dropdown list of weekdays is available. Cells D2:D12 have data validation lists with the source M2:M13. When a cell in this range is selected, a dropdown list of months is available.

Add the Combo box To add or edit the Combobox, open the Control Toolbox, and enter Design Mode: 1. 2. 3. 4. Choose View | Toolbars Select Control Toolbox Click the Design Mode button Click on the Combo box button, to activate that tool.

5. Click on an empty area of the worksheet, to add a combo box Open the Properties Window To format the combo box, open the properties window: 1. Select the combo box 2. On the Control Toolbox, click the Properties button

Change the Combo box Properties

Name the Combo box


1. In the Properties window, click in the Name box 2. Type a name for the combo box. In this example, the name is: TempCombo Change the Font and Font Size 1. In the Properties window, click in the Font property, and click the ... button 2. In the Font dialog box, select a font, font size, and other settings that you want for your combo box.

1. Click OK Set the Number of Rows 1. In the Properties window, click in the ListRows box 2. Type the number of rows that you want displayed in the dropdown. In this example, the setting is: 12 Turn on AutoComplete 1. In the Properties window, click in the MatchEntry property 2. From the dropdown list, select 1frmMatchEntryComplete

Exit Design Mode 1. Close the Properties window 2. On the Control Toolbox, click the Exit Design Mode button

Add the Code Visual Basic for Applications (VBA) code is required to make the combo box appear when you double-click in a cell that contains a data validation list. Copy the following code:
'========================== Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, _ Cancel As Boolean) Dim str As String Dim cboTemp As OLEObject Dim ws As Worksheet Set ws = ActiveSheet Cancel = True Set cboTemp = ws.OLEObjects("TempCombo") On Error Resume Next With cboTemp 'clear and hide the combo box .ListFillRange = "" .LinkedCell = "" .Visible = False End With On Error GoTo errHandler If Target.Validation.Type = 3 Then 'if the cell contains a data validation list Application.EnableEvents = False 'get the data validation formula str = Target.Validation.Formula1 str = Right(str, Len(str) - 1) With cboTemp 'show the combobox with the list .Visible = True .Left = Target.Left .Top = Target.Top .Width = Target.Width + 5 .Height = Target.Height + 5 .ListFillRange = ws.Range(str).Address .LinkedCell = Target.Address End With cboTemp.Activate End If errHandler: Application.EnableEvents = True Exit Sub End Sub '========================================= Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim str As String Dim cboTemp As OLEObject Dim ws As Worksheet Set ws = ActiveSheet Set cboTemp = ws.OLEObjects("TempCombo") On Error Resume Next If cboTemp.Visible = True Then With cboTemp .Top = 10 .Left = 10

.ListFillRange = "" .LinkedCell = "" .Visible = False .Value = "" End With End If errHandler: Application.EnableEvents = True Exit Sub End Sub '==================================== 'Optional code to move to next cell if Tab or Enter are pressed 'from code by Ted Lanham Private Sub TempCombo_KeyDown(ByVal _ KeyCode As MSForms.ReturnInteger, _ ByVal Shift As Integer) Select Case KeyCode Case 9 'Tab ActiveCell.Offset(0, 1).Activate Case 13 'Enter ActiveCell.Offset(1, 0).Activate Case Else 'do nothing End Select End Sub '====================================

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Choose Edit | Paste, to paste the code onto the sheet module, where the cursor is flashing. 3. Choose File | Close and Return to Microsoft Excel. Test the Code 1. Double-click on one of the cells that contains a data validation list. 2. The combo box will appear 3. Select an item from the combo box dropdown list 4. Click on a different cell, to select it 5. The selected item appears in previous cell, and the combo box disappears.
Download the sample file

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation

10. Data Validation -- Combo Box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Custom Validation Criteria Examples


Prevent Duplicates Limit the Total No Leading or Trailing Spaces Prohibit Weekend Dates Prevent Duplicates Prevent duplicate entries in a range on the worksheet. In this example, Employee Numbers will be entered in cells B3:B10. 1. Select cells B3:B10 2. Choose Data|Data Validation 3. Choose Allow: Custom 4. For the formula, use COUNTIF to count the occurrences of the value in cell B3, in the range $B$3:$B$10. The result must be 1 or 0: =COUNTIF($B$3:$B$10,B3)<=1 Limit the Total Prevent entry of a value that will cause a range to exceed a set total. In this example, the total budget cannot exceed $3500. The budget amounts are in cells C3:C7 1. Select cells C3:C7 2. Choose Data|Data Validation 3. Choose Allow: Custom 4. For the formula, use SUM to total the values in the range $C$3:$C$7. The result must be less than or equal to

$3500: =SUM($C$3:$C$7)<=350

No Leading or Trailing Spaces Prevent users from adding spaces before or after the text in the entry. The TRIM function removes spaces before and after the text. This formula checks that the entry is equal to the trimmed entry. 1. Select cell B2 2. Choose Data|Data Validation 3. Choose Allow: Custom 4. For the formula, enter: =B2=TRIM(B2) Prohibit Weekend Dates Prevent entry of dates that fall on Saturday or Sunday. The WEEKDAY function returns the number for the date entered, and values of 1 (Sunday) and 7 (Saturday) are not allowed. 1. Select cell B2 2. Choose Data|Data Validation 3. Choose Allow: Custom 4. For the formula, enter: =AND(WEEKDAY(B2)<>1,WEEKDAY(B2)<>7) 1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box

13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Dependent Dropdowns from a Sorted List


Set up the Workbook Create a Data Validation Dropdown List Create a Dependent Dropdown List Test the Validation

Download the zipped sample file

You can limit the choices in a Data Validation list, by using named ranges and the INDIRECT function, as explained here: Data Validation -- Create Dependent Lists Another method is to use the OFFSET function, to extract items from a sorted list, as described below. In this example, a region is selected in one column, and the customers in that region will appear in the data validation list in the adjacent cell. Set up the Workbook Two worksheets are required in this workbook. 1. Delete all sheets except Sheet1 and Sheet2 2. Rename Sheet1 as ValidationSample 3. Rename Sheet2 as ValidationLists On the ValidationLists sheet, type the lists that will be used in the data validation dropdowns: 1. In cells A1:B20 type a list of Regions and Customers Note: This list must be sorted by Region 2. In cells D1:D4 type a list of Regions Name the following ranges (there are Naming instructions here:

Name a Range): 1. 2. 3. 4. Name cell A1 as RegionStart Name column A as RegionColumn Name column B as CustColumn Name range D2:D4 as RegionList

Create a Data Validation Dropdown List On the ValidationSample sheet, type the headings Region and Customer, in cells B1 and C1. The next step is to create the Region data validation dropdown lists in column B.

Cells B2:B10 have data validation lists with the source RegionList. When a cell in this range is selected, a dropdown list of Regions is available. The formula for the list is: =IF(C2="",RegionList,INDEX(RegionColumn,MATCH(C2,CustColumn,0))) The complete region list is shown if no customer has been selected. However, if a customer has been selected in the adjacent cell, only that customer's region is shown in the Region dropdown list.

There are detailed instructions for creating data validation lists here: Data Validation -Introduction Create a Dependent Dropdown List The next step is to create the dependent data validation dropdown lists in column C. 1. In cell B2, select Ontario from the dropdown list. (If the cell is left empty, an error message may occur, when creating the dependent validation in column C.) 2. Select cells C2:C10 3. Choose Data | Validation 4. From the Allow dropdown, choose List 5. In the Source box, type the following formula: =OFFSET(RegionStart,MATCH(B2,RegionColumn,0)-1,1,COUNTIF(RegionColumn,B2),1)

The OFFSET function has the following arguments:

We want the OFFSET function to return a reference to the range of cells that contains the Ontario customers. Reference: In our formula, the reference is RegionStart, cell A1 on the ValidationLists sheet. Rows: How many rows down from the reference cell should our range start? The MATCH function finds the first instance of Ontario in the RegionColumn, in row 6. We subtract 1 from this number, because the starting cell is in row 1. Columns: We want a range that is 1 column to the right of the RegionStart reference. Height: The COUNTIF function counts the number of times that region is entered in the RegionColumn. There are 9 customers in the Ontario region. Width: We want a range that is 1 column wide 6. Click OK Test the Validation 1. Select cell C2 2. Click the data validation dropdown arrow 3. A list of Ontario customers is displayed.
Download the zipped sample file

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10. Data Validation -- Combo Box 11. Data Validation -- Combo Box using Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Create Dependent Lists


Download a sample file Create Named Lists Apply the Data Validation Test the Data Validation Using Two-Word Items Using Items with Illegal Characters Using Dynamic Lists

You can limit the choices in a Data Validation list, by using named ranges and the INDIRECT function. In this example, if Fruit is selected as the Category, only Fruit appears in the Item drop-down list. Another method is to use the OFFSET function, to extract items from a sorted list, as described here: Dependent Dropdowns from a Sorted List Create Named Lists Start by creating Named Lists, which will be the choices in the Data Validation cells. In this example, the first list will be named Produce. It contains the Produce categories -- Fruit and Vegetable. 1. Create the first Named List a. In an empty area of the workbook, type the entries you want to see in the drop-down list. These should be one-word entries, to match the dependent list names that will be created. (If you need to use multiple word entries, see the instructions here.) b. Select the cells in the list (but not the heading). c. Click in the Name box, to the left of the formula bar d. Type a one-word name for the list, e.g. Produce. e. Press the Enter key.

2. Create the supporting Named Lists a. Type the entries you want to see in the drop-down list for one of the Produce categories. b. Select the cells in the list. c. Click in the Name box, to the left of the formula bar d. Type a one-word name for the list, e.g. Fruit. This name must be exactly the same as the matching entry in the Produce list. e. Press the Enter key. f. Create another list with the items for the next category -- Vegetable in this example.

Apply the Data Validation The cells in the Category column will allow a List. The cells in the Item column will use the INDIRECT function to select a list.. 1. Apply the Data Validation a) Select the cells in which you want to apply data validation using the Category List b) From the Data menu, choose Validation.

c) From the Allow drop-down list, choose List d) In the Source box, type an equal sign and the list name, for example: =Produce e) Click OK.

2. Create the Dependent Data Validation a. Select the cells in which you want to apply data validation using the Fruit or Vegetable List, dependent on which Category has been selected b. From the Data menu, choose Validation. c. From the Allow drop-down list, choose List d. In the Source box, type an equal sign and INDIRECT function, referring to the first data cell in the Category column: =INDIRECT(A2) e. Click OK. Note: If cell A2 is empty, you'll see the message shown at right. Click Yes to continue

Test the Data Validation Cells in the Category column will display items in the Produce List. Cells in the Item column will show items from the Fruit or Vegetable List, depending which has been selected in the Category column Using Two-Word Items You may need to have two-word items in the first drop-down list. For example, your choices are 'Red Fruit', 'Green Fruit' and 'Yellow Fruit' 1. Create the first named range and dropdown list as described above. 2. Create the supporting named lists, using one-word names, e.g. RedFruit, GreenFruit, YellowFruit 3. For the second dropdown, choose to Allow: List, and use a formula that removes the spaces from the names. For example: =INDIRECT(SUBSTITUTE(A2," ",""))

Using Items with Illegal Characters You may need items in the first drop-down list that contain characters not allowed in range names, such as the ampersand (&). For example, your choices are 'Red Fruit', 'Green Fruit' and 'Yellow & Orange Fruit'. For the dependent lists, you can create ranges with oneword names, such as YOFruit. Then, you can create a lookup table, which lists each item in the first dropdown list, and the range where its dependent items will be stored. To start, create the item lists and the first drop-down: 1. Create the first named range and drop-down list as described above. In this example, the range is named FruitList, with values in cells A6:A8. The drop-down list in cell A2 uses FruitList as its source. 2. Create the dependent lists, and name them, using one-word names, e.g. RedFruit, GreenFruit, YOFruit. In this example, RedFruit is in A11:A12, YOFruit is in B11:B12 and GreenFruit is in C11:C12. 3. Select an item from the drop-down list in cell A2. Next, you'll create the lookup table, to match each item with its dependent items' range name. 1. In the column to the right of the FruitList range, enter the range name for each item's dependent list. For example, YOFruit is entered as the dependent range name for Yellow & Orange Fruit. 2. Name the lookup table. In this example, the range A6:B8 is named NameLookup. 3. Select cell B2, and from the Data menu, choose Validation. 4. Choose to Allow: List. 5. For the Source, enter a formula that uses a VLookup formula to find the dependent list's range name. For example:

=INDIRECT(VLOOKUP(A2,NameLookup ,2,0)) With Green Fruit selected in cell A2, the VLookup formula will return GreenFruit as the range name for the dependent list. The GreenFruit list will be displayed in cell B2's drop-down.

Using Dynamic Lists

Because the INDIRECT function only works with references, not Download a sample file for Dynamic Lists formulas, the previous method won't work with dynamic lists. Instead, you can use the following method: 1. Create the first named range and dropdown list as described above. 2. Create the supporting named lists, and name the first cell in each range, e.g. cell B1 is named Fruit and cell C1 is named Vegetables. 3. Name the column in which each list is located, e.g. column B is named FruitCol and column C is named VegetablesCol 4. For the second dropdown, choose to Allow: List, and use a formula that calculates the lookup range. For example, if the first dropdown list is in cell E2: =OFFSET(INDIRECT($E2),0,0,COUNTA(INDIRECT(E2&"Col") ),1) if two-word items will be used, you can include the SUBSTITUTE function in the formula: =OFFSET(INDIRECT(SUBSTITUTE($F2," ","")),0,0,COUNTA(INDIRECT(SUBSTITUTE($F2," ","")&"Col")),1) Download a sample file for Dynamic Lists 1. Data Validation 2. Data Validation -- Create Dependent Lists

3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Documentation


Document a Worksheet's Data Validation The following procedure creates a text file with a list of the active worksheet's data validation. For example: A11 D4 D5 D8 D11 Whole Number List List Text Length Custom Less Than or Equal to 3 Yes,No =DaysList Less Than 5 =AND($A$1<>"",$A$3<>"")

Download the zipped sample file

Thanks to J.E. McGimpsey for generously sharing his code.

Sub DataValDocumenter() 'adapted from code posted by J.E. McGimpsey 2005-02-03 'http://www.mcgimpsey.com/excel/index.html Dim sVal(0 To 2) As Variant Dim rValidation As Range Dim rCell As Range Dim nFile As Long Dim sC As String Dim strDV As String sC = vbTab On Error Resume Next Set rValidation = Cells.SpecialCells(xlCellTypeAllValidation) On Error GoTo 0 If Not rValidation Is Nothing Then nFile = FreeFile Open "test.txt" For Output As #nFile For Each rCell In rValidation With rCell.Validation sVal(0) = Choose(.Type + 1, "Input Only", _ "Whole Number", "Decimal", "List", "Date", _ "Time", "Text Length", "Custom") sVal(1) = .Formula1 sVal(2) = .Formula2 Select Case .Type Case xlValidateWholeNumber, xlValidateDecimal, _ xlValidateDate, xlValidateTime, xlValidateCustom Select Case .Operator Case xlAnd strDV = "Between" & sC & sVal(1) & sC & "And" & sC & sVal(2) Case xlNotBetween strDV = "Not Between" & sC & sVal(1) & sC & "And" & sC &

sVal(2)

Case xlEqual strDV = "Equal to" & sC & sVal(1) Case xlNotEqual strDV = "Not Equal to" & sC & sVal(1) Case xlGreater strDV = "Greater Than" & sC & sVal(1) Case xlLess strDV = "Less Than" & sC & sVal(1) Case xlGreaterEqual strDV = "Greater Than or Equal to" & sC & sVal(1) Case xlLessEqual strDV = "Less Than or Equal to" & sC & sVal(1) Case Else 'do nothing End Select Case Else strDV = sVal(1) End Select End With strDV = sC & sVal(0) & sC & strDV Print #nFile, rCell.Address(False, False) & strDV Erase sVal Next rCell Close #nFile End If End Sub

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Tips and Quirks


Refer to a Source List on a Different Worksheet Use Dynamic Lists Data Validation Font Size and List Length Data Validation Dropdowns and Change Events Data Validation Dropdown Arrows Not Visible Invalid Entries are Allowed Data Validation on a Protected Sheet Make the Dropdown List Temporarily Wider Make the Dropdown List Appear Larger -- Zoom in when specific cell is selected -- Zoom in when specific cells are selected -- Zoom in when any cell with data validation is selected

Refer to a Source List on a Different Worksheet When you try to create a data validation dropdown list, and refer to a source list on a different worksheet, you may see an error message: "You may not use references to other worksheets of workbooks for Data Validation criteria." To avoid this problem, name the list on the other worksheet, then refer to the named range, as described here: Data Validation If the list is in a different workbook, you can use the technique described here: Use a List from Another Workbook

Use Dynamic Lists Some lists change frequently, with items being added or removed. If the list is the source for a Data Validation dropdown, use a dynamic formula to name the range, and the dropdown list will be automatically updated. For instructions, view this page: Create a Dynamic Range Data Validation Dropdowns and Change Events In Excel 2000 and later versions, selecting an item from a Data Validation dropdown list will trigger a Change event. This means that code can automatically run after a user selects an item from the list. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList.zip file. In Excel 97, selecting an item from a Data Validation dropdown list does not trigger a Change event, unless the list items have been typed in the Data Validation dialog box. In this version, you can add a button to the worksheet, and run the code by clicking the button. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97.zip file. Another option in Excel 97 is to use the Calculate event to run the code. To do this, refer to the cell with data validation in a formula on the worksheet, e.g. =MATCH(C3,CategoryList,0). Then, add the filter code to the worksheet's Calculate event. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97Calc.zip file.

Data Validation Dropdown Arrows Not Visible Occasionally, data validation dropdown arrows are not visible on the worksheet, in cells where you know that data validation lists have been created. The following are the most common reasons for missing arrows. Active Cell Only Only the active cell on a worksheet will display a data validation dropdown arrow. To mark cells that contain data validation lists, you can colour the cells, or add a comment. If you require visible arrows for all cells that contain lists, you can use combo boxes instead of data validation, and those arrows will be visible at all times. To create a combo box, choose View|Toolbars, and select either the Control Toolbox or the Forms toolbar. Hidden Objects If objects are hidden on the worksheet, the data validation dropdown arrows will also be hidden. To make objects visible, choose Tools|Options, and on the View tab, under Objects, select Show all. Dropdown Option In the Data Validation dialog box, you can turn off the option for a dropdown list. To turn it back on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, add a check mark to In-cell dropdown 4. Click OK Freeze Panes In Excel 97, if a Data Validation dropdown list is in a frozen pane of the window, the dropdown arrow does not appear when the cell is selected. As a workaround, use Window|Split instead of Window|Freeze Panes This problem has been corrected in later versions.

Without frozen panes

Corruption If none of the above solutions explains the missing dropdown With frozen panes arrows, the worksheet may be corrupted. Try copying the data to a new worksheet or workbook, and the dropdown arrows may reappear. Or, try to repair the file as you open it: 1. In Excel, choose File | Open

2. Select the file with the missing data validation arrows 3. On the Open button, click the arrow 4. Click Open and Repair 5. When prompted, click Repair.

Invalid Entries Are Allowed Although you have created data validation dropdown arrows on some cells, users may be able to type invalid entries. The following are the most common reasons for this. Error Alert If the Error Alert is turned off, users will be able to type any entry, without receiving an error message. To turn the alert on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Error Alert tab, add a check mark to the Show error alert after invalid data is entered box. 4. Click OK Blank Cells in Source List If the source list is a named range that contains blank cells, users may be able to type any entry, without receiving an error message. To turn prevent this: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, remove the check mark from the Ignore blank box. 4. Click OK Note: If the source list contains blank cells, and is a range address, e.g. $A$1:$A$10, it will block invalid entries with Ignore blank on or off.

Data Validation on a Protected Sheet In Excel 2000 and earlier versions, you can change the selection in a data validation dropdown, if the list is from a range on the worksheet. If the list is typed in the data validation dialog box, the selection can't be changed. In Excel 2002 and later versions, neither type of dropdown list can be changed if the cell is locked and the sheet is protected. This MSKB article has information on the previous behaviour: XL97: Error When Using Validation Drop-Down List Box http://support.microsoft.com/default.aspx?id=157484

Make the Dropdown List Temporarily Wider The Data Validation dropdown is the width of the cell that it's in, to a minimum of about 3/4". You could use a SelectionChange event to temporarily widen the column when it's active, then make it narrower when you select a cell in another column. For example, with Data Validation cells in column D:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target.Column = 4 Then Target.Columns.ColumnWidth = 20 Else Columns(4).ColumnWidth = 5 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the column reference from 4 to match your worksheet.

Data Validation Font Size and List Length The font size in a data validation list can't be changed, nor can its default list length, which has a maximum of eight rows. If you reduce the zoom setting on a worksheet, it can be almost impossible to read the items in the dropdown list, as in the example at right. One workaround is to use programming, and a combo box from the Control Toolbox, to overlay the cell with data validation. If the user double-clicks on a data validation cell, the combobox appears, and they can choose from it. There are instructions here.

Make the Dropdown List Appear Larger In a Data Validation dropdown list, you can't change the font or font size. To make the text appear larger, you can use an event procedure (three examples are shown below) to increase the zoom setting when the cell is selected. (Note: this can be a bit jumpy) Or, you can use code to display a combobox, as described in the previous section. Zoom in when specific cell is selected If cell A2 has a data validation list, the following code will change the zoom setting to 120% when that cell is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$2" Then ActiveWindow.Zoom = 120 Else ActiveWindow.Zoom = 100 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the cell reference from $A$2 to match your worksheet.

Zoom in when specific cells are selected If several cells have a data validation list, the following code will change the zoom setting to 120% when any of those cells are selected. In this example, cells A1, B3 and D9 have data validation.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Intersect(Target, Range("A1,B3,D9")) Is Nothing Then ActiveWindow.Zoom = 100 Else ActiveWindow.Zoom = 120 End If End Sub

Zoom in when any cell with a data validation list is selected The following code will change the zoom setting to 120% when any cell with a data validation list is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim lZoom As Long Dim lZoomDV As Long Dim lDVType As Long lZoom = 100 lZoomDV = 120 lDVType = 0 Application.EnableEvents = False On Error Resume Next lDVType = Target.Validation.Type On Error GoTo errHandler If lDVType <> 3 Then With ActiveWindow If .Zoom <> lZoom Then .Zoom = lZoom End If End With Else With ActiveWindow If .Zoom <> lZoomDV Then .Zoom = lZoomDV End If

End With End If exitHandler: Application.EnableEvents = True Exit Sub errHandler: GoTo exitHandler End Sub

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List H

Excel -- Data Validation -- Hide Previously Used Items in Dropdown


Thanks to Excel MVP, Peo Sjoblom, who contributed the original formula for this technique, and to Daniel.M, who suggested the enhanced formulas. Set up the Main Table Create the List of Items Create the Validation List Apply the Data Validation

To download a zipped sample file, click here: Data Validation -- Hidden Items -Sample

Test the Data Validation Dependent Data Validation

You can limit the choices in a Data Validation list, hiding items that have been previously selected. For example, if you are assigning employees to a shift, you want to avoid assigning the same employee twice. In the dropdown list, the names that have been used are removed. Set up the Main Table Start by setting up the table in which you want to use the Data Validation. In this example, the worksheet is named 'Schedule' and the range A1:C7 is being used. Column B will have Data Validation applied. Create the List of Items Create a list which contains the items you want to see in the dropdown list. Here, the employee names have been entered in cells A1:A6, on a sheet named 'Employees' Create the Validation List A) Enter a formula to calculate if a name has been used. 1. On the Employees sheet, in cell B1, enter the following formula: =IF(COUNTIF(Schedule!$B$2:$B$7,A1)>=1,"",ROW())

2. Copy the formula down to cell B6.

This formula counts the occurrences of "Bert" in cells B2:B7 on the Schedule worksheet. If the count is greater than or equal to 1, the cell will appear blank. Otherwise, the row number will be displayed. B) Create the list of unused names The next step is to create a multi-cell array formula which will move any blank cells to the end of the list. 1. Select cells C1:C6 2. Enter the following array formula (the formula is long, and should be all on one line) =IF(ROW(A1:A6)-ROW(A1)+1>COUNT(B1:B6),"", INDEX(A:A,SMALL(B1:B6,ROW(INDIRECT("1:"&ROWS(A1:A6)))))) 3. Press Ctrl+Shift+Enter to enter the array formula in cells C1:C6 Single-Cell Formula Alternative If you'd prefer a single-cell formula (easier to edit), you could use this formula, also by Daniel.M. He recommends it for small ranges (<=200 cells): 1. Select cell C1 2. Enter the following formula (the formula is long, and should be all on one line) =IF(ROW(A1)-ROW(A$1)+1>COUNT(B$1:B$6),"", INDEX(A:A,SMALL(B$1:B$6,1+ROW(A1)-ROW(A$1)))) 3. Press Enter 4. Copy the formula down to row 6 Name the Validation List 1. Choose Insert>Name>Define 2. In the Names in workbook box, type a one-word name for the range, e.g. NameCheck. 3. In the Refers to box, type the following formula (all on one line): =OFFSET(Employees!$C$1,0,0,COUNTA(Employees!$C$1:$C$6)COUNTBLANK(Employees!$C$1:$C$6),1) 4. Click OK

Apply the Data Validation 1. Select the cells in which you want to apply data validation using the Validation list 2. From the Data menu, choose Validation. 3. From the Allow dropdown list, choose List 4. In the Source box, type an equal sign and the list name, for example: =NameCheck 5. Click OK.

Test the Data Validation The dropdown list in column B shows only the names that haven't been used. Other names have been removed. To download a zipped sample file, click here: Data Validation -- Hidden Items -- Sample Dependent Data Validation This technique can be modified, and used with Dependent Data Validation, as in the zipped sample workbook found here: Hide Previously Used - Dependent

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Display Input Messages in a Text Box


Set up the Workbook Create a Data Validation Dropdown List Add the Text Box Name the Text Box Add the Code Test the Code You can use a Data Validation Input Message to display a message when a cell is selected. However, the font can't be changed, nor can message box size be controlled. To overcome these limitations, you can create a text box to display the message, and use programming to make it appear if cells that contain a data validation Input Message are selected. Set up the Workbook Two worksheets are required in this workbook. 1. Delete all sheets except Sheet1 and Sheet2 2. Rename Sheet1 as ValidationSample 3. Rename Sheet2 as ValidationLists On the ValidationLists sheet, type the lists that will be used in the data validation dropdowns: Tip: Use the AutoFill feature to create the lists 1. In cells A1:A7 type a list of weekdays 2. In cells C1:C12 type a list of months Name the lists (there are Naming instructions here: Name a Range): 1. Name the range A1:A7 as DayList 2. Name the range C1:C12 as MonthList

Download the zipped sample file

Create a Data Validation Dropdown List The next step is to create the data validation dropdown lists. There are detailed instructions here: Data Validation -- Introduction

Cells C5:C15 have data validation lists with the source DayList. When a cell in this range is selected, a dropdown list of weekdays is available. Include an Input Message, as described here: Display Messages to the User . The message used in the sample file is: Title: Activation Day Message: Please select the weekday in which the product was originally purchased, not the weekday in which it was first used. If you are not sure, please leave this cell blank, then check with your manager, and fill in the weekday later. Cells D5:D15 have data validation lists with the source MonthList. When a cell in this range is selected, a dropdown list of months is available. Include an Input Message. The message used in the sample file is: Title: Activation Month Message: Please select the month in which the product was originally purchased, not the month in which it was first used. If you are not sure, please leave this cell blank, then check with your manager, and fill in the month later.

Add the Text box 1. If the Drawing Toolbar is not visible, display it (View | Toolbars) 2. On the Drawing Toolbar, click the Text Box tool. 3. Draw a text box at the top of the worksheet, large enough to hold your messages. 4. Type some sample text, e.g. "This is the Input Message" 5. Format the text box with the font and font size you'd like. 6. Right-click on the border of the text box, and choose Format Text Box 7. Select the Properties tab 8. Select Don't move or size with cells 9. Remove the check mark from Print object 10. Click OK Name the Text box 1. Click on the border of the text box, to select it 2. Click in the Name Box, at the left of the Formula Bar 3. Type the text box name: txtInputMsg 4. Press the Enter key

Add the Code Visual Basic for Applications (VBA) code is required to make the text box appear when you select a cell that contains a data validation input message. It copies the data validation Input Message and Input Title to the text box, and makes the title bold. Copy the following code:
'========================================= Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim strTitle As String Dim strMsg As String Dim lDVType As Long Dim sTemp As Shape Dim ws As Worksheet Application.EnableEvents = False Set ws = ActiveSheet Set sTemp = ws.Shapes("txtInputMsg") On Error Resume Next lDVType = 0 lDVType = Target.Validation.Type On Error GoTo errHandler If lDVType = 0 Then sTemp.TextFrame.Characters.Text = "" sTemp.Visible = msoFalse Else If Target.Validation.InputTitle <> "" Or _ Target.Validation.InputMessage <> "" Then strTitle = Target.Validation.InputTitle & Chr(10) strMsg = Target.Validation.InputMessage With sTemp.TextFrame .Characters.Text = strTitle & strMsg .Characters.Font.Bold = False .Characters(1, Len(strTitle)).Font.Bold = True End With sTemp.Visible = msoTrue Else sTemp.TextFrame.Characters.Text = "" sTemp.Visible = msoFalse End If End If errHandler: Application.EnableEvents = True Exit Sub End Sub '====================================

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Choose Edit | Paste, to paste the code onto the sheet module, where the cursor is flashing. 3. Choose File | Close and Return to Microsoft Excel. Test the Code

1. Select one of the cells that contains a data validation input message. 2. The text box will appear 3. Select a cell that doesn't contain a data validation in put message 4. The text box disappears.
Download the zipped sample file

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10. Data Validation -- Combo Box 11. Data Validation -- Combo Box using Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Tips and Quirks


Refer to a Source List on a Different Worksheet Use Dynamic Lists Data Validation Font Size and List Length Data Validation Dropdowns and Change Events Data Validation Dropdown Arrows Not Visible Invalid Entries are Allowed Data Validation on a Protected Sheet Make the Dropdown List Temporarily Wider Make the Dropdown List Appear Larger -- Zoom in when specific cell is selected -- Zoom in when specific cells are selected -- Zoom in when any cell with data validation is selected

Refer to a Source List on a Different Worksheet When you try to create a data validation dropdown list, and refer to a source list on a different worksheet, you may see an error message: "You may not use references to other worksheets of workbooks for Data Validation criteria." To avoid this problem, name the list on the other worksheet, then refer to the named range, as described here: Data Validation If the list is in a different workbook, you can use the technique described here: Use a List from Another Workbook

Use Dynamic Lists Some lists change frequently, with items being added or removed. If the list is the source for a Data Validation dropdown, use a dynamic formula to name the range, and the dropdown list will be automatically updated. For instructions, view this page: Create a Dynamic Range Data Validation Dropdowns and Change Events In Excel 2000 and later versions, selecting an item from a Data Validation dropdown list will trigger a Change event. This means that code can automatically run after a user selects an item from the list. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList.zip file. In Excel 97, selecting an item from a Data Validation dropdown list does not trigger a Change event, unless the list items have been typed in the Data Validation dialog box. In this version, you can add a button to the worksheet, and run the code by clicking the button. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97.zip file. Another option in Excel 97 is to use the Calculate event to run the code. To do this, refer to the cell with data validation in a formula on the worksheet, e.g. =MATCH(C3,CategoryList,0). Then, add the filter code to the worksheet's Calculate event. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97Calc.zip file.

Data Validation Dropdown Arrows Not Visible Occasionally, data validation dropdown arrows are not visible on the worksheet, in cells where you know that data validation lists have been created. The following are the most common reasons for missing arrows. Active Cell Only Only the active cell on a worksheet will display a data validation dropdown arrow. To mark cells that contain data validation lists, you can colour the cells, or add a comment. If you require visible arrows for all cells that contain lists, you can use combo boxes instead of data validation, and those arrows will be visible at all times. To create a combo box, choose View|Toolbars, and select either the Control Toolbox or the Forms toolbar. Hidden Objects If objects are hidden on the worksheet, the data validation dropdown arrows will also be hidden. To make objects visible, choose Tools|Options, and on the View tab, under Objects, select Show all. Dropdown Option In the Data Validation dialog box, you can turn off the option for a dropdown list. To turn it back on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, add a check mark to In-cell dropdown 4. Click OK Freeze Panes In Excel 97, if a Data Validation dropdown list is in a frozen pane of the window, the dropdown arrow does not appear when the cell is selected. As a workaround, use Window|Split instead of Window|Freeze Panes This problem has been corrected in later versions.

Without frozen panes

Corruption If none of the above solutions explains the missing dropdown With frozen panes arrows, the worksheet may be corrupted. Try copying the data to a new worksheet or workbook, and the dropdown arrows may reappear. Or, try to repair the file as you open it: 1. In Excel, choose File | Open

2. Select the file with the missing data validation arrows 3. On the Open button, click the arrow 4. Click Open and Repair 5. When prompted, click Repair.

Invalid Entries Are Allowed Although you have created data validation dropdown arrows on some cells, users may be able to type invalid entries. The following are the most common reasons for this. Error Alert If the Error Alert is turned off, users will be able to type any entry, without receiving an error message. To turn the alert on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Error Alert tab, add a check mark to the Show error alert after invalid data is entered box. 4. Click OK Blank Cells in Source List If the source list is a named range that contains blank cells, users may be able to type any entry, without receiving an error message. To turn prevent this: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, remove the check mark from the Ignore blank box. 4. Click OK Note: If the source list contains blank cells, and is a range address, e.g. $A$1:$A$10, it will block invalid entries with Ignore blank on or off.

Data Validation on a Protected Sheet In Excel 2000 and earlier versions, you can change the selection in a data validation dropdown, if the list is from a range on the worksheet. If the list is typed in the data validation dialog box, the selection can't be changed. In Excel 2002 and later versions, neither type of dropdown list can be changed if the cell is locked and the sheet is protected. This MSKB article has information on the previous behaviour: XL97: Error When Using Validation Drop-Down List Box http://support.microsoft.com/default.aspx?id=157484

Make the Dropdown List Temporarily Wider The Data Validation dropdown is the width of the cell that it's in, to a minimum of about 3/4". You could use a SelectionChange event to temporarily widen the column when it's active, then make it narrower when you select a cell in another column. For example, with Data Validation cells in column D:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target.Column = 4 Then Target.Columns.ColumnWidth = 20 Else Columns(4).ColumnWidth = 5 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the column reference from 4 to match your worksheet.

Data Validation Font Size and List Length The font size in a data validation list can't be changed, nor can its default list length, which has a maximum of eight rows. If you reduce the zoom setting on a worksheet, it can be almost impossible to read the items in the dropdown list, as in the example at right. One workaround is to use programming, and a combo box from the Control Toolbox, to overlay the cell with data validation. If the user double-clicks on a data validation cell, the combobox appears, and they can choose from it. There are instructions here.

Make the Dropdown List Appear Larger In a Data Validation dropdown list, you can't change the font or font size. To make the text appear larger, you can use an event procedure (three examples are shown below) to increase the zoom setting when the cell is selected. (Note: this can be a bit jumpy) Or, you can use code to display a combobox, as described in the previous section. Zoom in when specific cell is selected If cell A2 has a data validation list, the following code will change the zoom setting to 120% when that cell is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$2" Then ActiveWindow.Zoom = 120 Else ActiveWindow.Zoom = 100 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the cell reference from $A$2 to match your worksheet.

Zoom in when specific cells are selected If several cells have a data validation list, the following code will change the zoom setting to 120% when any of those cells are selected. In this example, cells A1, B3 and D9 have data validation.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Intersect(Target, Range("A1,B3,D9")) Is Nothing Then ActiveWindow.Zoom = 100 Else ActiveWindow.Zoom = 120 End If End Sub

Zoom in when any cell with a data validation list is selected The following code will change the zoom setting to 120% when any cell with a data validation list is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim lZoom As Long Dim lZoomDV As Long Dim lDVType As Long lZoom = 100 lZoomDV = 120 lDVType = 0 Application.EnableEvents = False On Error Resume Next lDVType = Target.Validation.Type On Error GoTo errHandler If lDVType <> 3 Then With ActiveWindow If .Zoom <> lZoom Then .Zoom = lZoom End If End With Else With ActiveWindow If .Zoom <> lZoomDV Then .Zoom = lZoomDV End If

End With End If exitHandler: Application.EnableEvents = True Exit Sub errHandler: GoTo exitHandler End Sub

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Use a List from Another Workbook


Create the Source List Create a Reference to the Source List Create the Dropdown List Create a Dynamic Range from Another Workbook You can use a list from another workbook as the source for a Data Validation dropdown list. For data validation to work, the workbook which contains the list must be open, in the same instance of Excel. You could create the list in a workbook that is always open, but hidden, such as the Personal.xls workbook.

Create the Source List The following instructions assume you have a workbook named DatValWb.xls, which contains a range named CustName. For instructions on creating a named range, refer to Naming Ranges .

Create a Reference to the Source List


1. 2. 3. 4. Open the workbook in which you wish to use the list in Data Validation. Choose Insert>Name>Define Type a name for the List, e.g. MyList In the refers to box, type a reference to the named range. Start with an equal sign, then the workbook name and an exclamation mark, followed by the range name, e.g. =DataValWb.xls! CustName 5. Click OK

Create the Dropdown List


1. 2. 3. 4. Select the cells in which data validation will be set. Choose Data>Validation In the Allow box, choose List In the Source box, type the list name, preceded by an equal sign, e.g.: =MyList

5. Click OK

Create a Dynamic Range from Another Workbook


You can create a dynamic range that refers to a dynamic range in another (open) workbook. 1. Create and save a workbook (MyLists.xls, in this example) 2. Enter a list of names in cells A1:A10 on Sheet 1. 3. To create a dynamic range, choose Insert|Name|Define Use Employees as the range name, and the following formula: =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A)) 4. Keep MyLists.xls open, and create and save a new workbook (Schedule.xls) 5. In Schedule.xls, create a range named EmployeeList with this formula: =MyLists.xls!Employees 6. In cell A1 of sheet1, enter the following formula: =EmployeeList 7. Copy the formula down to row 200 (or any row beyond the length of the dynamic range in MyList.xls). Note: many of the rows will contain a #VALUE! error. 8. In Schedule.xls, create another range, with the name NoErrors, and the formula: =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A)-COUNTIF(Sheet1! $A$1:$A$300,"#VALUE! ")) (all one line) 8. Use NoErrors as the source for your Data Validation list. 1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Tips and Quirks

Refer to a Source List on a Different Worksheet Use Dynamic Lists Data Validation Font Size and List Length Data Validation Dropdowns and Change Events Data Validation Dropdown Arrows Not Visible Invalid Entries are Allowed Data Validation on a Protected Sheet Make the Dropdown List Temporarily Wider Make the Dropdown List Appear Larger -- Zoom in when specific cell is selected -- Zoom in when specific cells are selected -- Zoom in when any cell with data validation is selected Refer to a Source List on a Different Worksheet When you try to create a data validation dropdown list, and refer to a source list on a different worksheet, you may see an error message: "You may not use references to other worksheets of workbooks for Data Validation criteria." To avoid this problem, name the list on the other worksheet, then refer to the named range, as described here: Data Validation If the list is in a different workbook, you can use the technique described here: Use a List from Another Workbook

Use Dynamic Lists Some lists change frequently, with items being added or removed. If the list is the source for a Data Validation dropdown, use a dynamic formula to name the range, and the dropdown list will be automatically updated. For instructions, view this page: Create a Dynamic Range Data Validation Dropdowns and Change Events In Excel 2000 and later versions, selecting an item from a Data Validation dropdown list will trigger a Change event. This means that code can automatically run after a user selects an item from the list. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList.zip file. In Excel 97, selecting an item from a Data Validation dropdown list does not trigger a Change event, unless the list items have been typed in the Data Validation dialog box. In this version, you can add a button to the worksheet, and run the code by clicking

the button. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97.zip file. Another option in Excel 97 is to use the Calculate event to run the code. To do this, refer to the cell with data validation in a formula on the worksheet, e.g. =MATCH(C3,CategoryList,0). Then, add the filter code to the worksheet's Calculate event. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97Calc.zip file.

Data Validation Dropdown Arrows Not Visible Occasionally, data validation dropdown arrows are not visible on the worksheet, in cells where you know that data validation lists have been created. The following are the most common reasons for missing arrows. Active Cell Only Only the active cell on a worksheet will display a data validation dropdown arrow. To mark cells that contain data validation lists, you can colour the cells, or add a comment. If you require visible arrows for all cells that contain lists, you can use combo boxes instead of data validation, and those arrows will be visible at all times. To create a combo box, choose View|Toolbars, and select either the Control Toolbox or the Forms toolbar. Hidden Objects If objects are hidden on the worksheet, the data validation dropdown arrows will also be hidden. To make objects visible, choose Tools|Options, and on the View tab, under Objects, select Show all. Dropdown Option In the Data Validation dialog box, you can turn off the option for a dropdown list. To turn it back on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, add a check mark to In-cell dropdown 4. Click OK Freeze Panes In Excel 97, if a Data Validation dropdown list is in a frozen pane of the window, the dropdown arrow does not appear when the cell is selected. As a workaround, use Window|Split instead of Window|Freeze Panes

Without frozen panes

This problem has been corrected in later versions.

Corruption If none of the above solutions explains the missing dropdown With frozen panes arrows, the worksheet may be corrupted. Try copying the data to a new worksheet or workbook, and the dropdown arrows may reappear. Or, try to repair the file as you open it: 1. 2. 3. 4. In Excel, choose File | Open Select the file with the missing data validation arrows On the Open button, click the arrow Click Open and Repair

5. When prompted, click Repair. Invalid Entries Are Allowed Although you have created data validation dropdown arrows on some cells, users may be able to type invalid entries. The following are the most common reasons for this. Error Alert If the Error Alert is turned off, users will be able to type any entry, without receiving an error message. To turn the alert on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Error Alert tab, add a check mark to the Show error alert after invalid data is entered box. 4. Click OK Blank Cells in Source List If the source list is a named range that contains blank cells, users may be able to type any entry, without receiving an error message. To turn prevent this: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, remove the check mark from the Ignore blank box.

4. Click OK Note: If the source list contains blank cells, and is a range address, e.g. $A$1:$A$10, it will block invalid entries with Ignore blank on or off. Data Validation on a Protected Sheet In Excel 2000 and earlier versions, you can change the selection in a data validation dropdown, if the list is from a range on the worksheet. If the list is typed in the data validation dialog box, the selection can't be changed. In Excel 2002 and later versions, neither type of dropdown list can be changed if the cell is locked and the sheet is protected. This MSKB article has information on the previous behaviour: XL97: Error When Using Validation Drop-Down List Box http://support.microsoft.com/default.aspx?id=157484

Make the Dropdown List Temporarily Wider The Data Validation dropdown is the width of the cell that it's in, to a minimum of about 3/4". You could use a SelectionChange event to temporarily widen the column when it's active, then make it narrower when you select a cell in another column. For example, with Data Validation cells in column D:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target.Column = 4 Then Target.Columns.ColumnWidth = 20 Else Columns(4).ColumnWidth = 5 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the column reference from 4 to match your worksheet.

Data Validation Font Size and List Length The font size in a data validation list can't be changed, nor can its default list length, which has a maximum of eight rows. If you reduce the zoom setting on a worksheet, it can be almost impossible to read the items in the dropdown list, as in the example at right. One workaround is to use programming, and a combo box from the Control Toolbox, to overlay the cell with data validation. If the user double-clicks on a data validation cell, the combobox appears, and they can choose from it. There are instructions here.

Make the Dropdown List Appear Larger In a Data Validation dropdown list, you can't change the font or font size. To make the text appear larger, you can use an event procedure (three examples are shown below) to increase the zoom setting when the cell is selected. (Note: this can be a bit jumpy) Or, you can use code to display a combobox, as described in the previous section. Zoom in when specific cell is selected If cell A2 has a data validation list, the following code will change the zoom setting to 120% when that cell is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$2" Then ActiveWindow.Zoom = 120 Else ActiveWindow.Zoom = 100 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the cell reference from $A$2 to match your worksheet.

Zoom in when specific cells are selected If several cells have a data validation list, the following code will change the zoom setting to 120% when any of those cells are selected. In this example, cells A1, B3 and D9 have data validation.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Intersect(Target, Range("A1,B3,D9")) Is Nothing Then ActiveWindow.Zoom = 100 Else ActiveWindow.Zoom = 120 End If End Sub

Zoom in when any cell with a data validation list is selected The following code will change the zoom setting to 120% when any cell with a data validation list is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim lZoom As Long Dim lZoomDV As Long Dim lDVType As Long lZoom = 100 lZoomDV = 120 lDVType = 0 Application.EnableEvents = False On Error Resume Next lDVType = Target.Validation.Type On Error GoTo errHandler If lDVType <> 3 Then With ActiveWindow If .Zoom <> lZoom Then .Zoom = lZoom End If End With Else With ActiveWindow If .Zoom <> lZoomDV Then .Zoom = lZoomDV End If

End With End If exitHandler: Application.EnableEvents = True Exit Sub errHandler: GoTo exitHandler End Sub

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Tips and Quirks


Refer to a Source List on a Different Worksheet Use Dynamic Lists Data Validation Font Size and List Length Data Validation Dropdowns and Change Events Data Validation Dropdown Arrows Not Visible Invalid Entries are Allowed Data Validation on a Protected Sheet Make the Dropdown List Temporarily Wider Make the Dropdown List Appear Larger -- Zoom in when specific cell is selected -- Zoom in when specific cells are selected -- Zoom in when any cell with data validation is selected

Refer to a Source List on a Different Worksheet When you try to create a data validation dropdown list, and refer to a source list on a different worksheet, you may see an error message: "You may not use references to other worksheets of workbooks for Data Validation criteria." To avoid this problem, name the list on the other worksheet, then refer to the named range, as described here: Data Validation If the list is in a different workbook, you can use the technique described here: Use a List from Another Workbook

Use Dynamic Lists Some lists change frequently, with items being added or removed. If the list is the source for a Data Validation dropdown, use a dynamic formula to name the range, and the dropdown list will be automatically updated. For instructions, view this page: Create a Dynamic Range Data Validation Dropdowns and Change Events In Excel 2000 and later versions, selecting an item from a Data Validation dropdown list will trigger a Change event. This means that code can automatically run after a user selects an item from the list. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList.zip file. In Excel 97, selecting an item from a Data Validation dropdown list does not trigger a Change event, unless the list items have been typed in the Data Validation dialog box. In this version, you can add a button to the worksheet, and run the code by clicking the button. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97.zip file. Another option in Excel 97 is to use the Calculate event to run the code. To do this, refer to the cell with data validation in a formula on the worksheet, e.g. =MATCH(C3,CategoryList,0). Then, add the filter code to the worksheet's Calculate event. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97Calc.zip file.

Data Validation Dropdown Arrows Not Visible Occasionally, data validation dropdown arrows are not visible on the worksheet, in cells where you know that data validation lists have been created. The following are the most common reasons for missing arrows. Active Cell Only Only the active cell on a worksheet will display a data validation dropdown arrow. To mark cells that contain data validation lists, you can colour the cells, or add a comment. If you require visible arrows for all cells that contain lists, you can use combo boxes instead of data validation, and those arrows will be visible at all times. To create a combo box, choose View|Toolbars, and select either the Control Toolbox or the Forms toolbar. Hidden Objects If objects are hidden on the worksheet, the data validation dropdown arrows will also be hidden. To make objects visible, choose Tools|Options, and on the View tab, under Objects, select Show all. Dropdown Option In the Data Validation dialog box, you can turn off the option for a dropdown list. To turn it back on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, add a check mark to In-cell dropdown 4. Click OK Freeze Panes In Excel 97, if a Data Validation dropdown list is in a frozen pane of the window, the dropdown arrow does not appear when the cell is selected. As a workaround, use Window|Split instead of Window|Freeze Panes This problem has been corrected in later versions.

Without frozen panes

Corruption If none of the above solutions explains the missing dropdown With frozen panes arrows, the worksheet may be corrupted. Try copying the data to a new worksheet or workbook, and the dropdown arrows may reappear. Or, try to repair the file as you open it: 1. In Excel, choose File | Open

2. Select the file with the missing data validation arrows 3. On the Open button, click the arrow 4. Click Open and Repair 5. When prompted, click Repair.

Invalid Entries Are Allowed Although you have created data validation dropdown arrows on some cells, users may be able to type invalid entries. The following are the most common reasons for this. Error Alert If the Error Alert is turned off, users will be able to type any entry, without receiving an error message. To turn the alert on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Error Alert tab, add a check mark to the Show error alert after invalid data is entered box. 4. Click OK Blank Cells in Source List If the source list is a named range that contains blank cells, users may be able to type any entry, without receiving an error message. To turn prevent this: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, remove the check mark from the Ignore blank box. 4. Click OK Note: If the source list contains blank cells, and is a range address, e.g. $A$1:$A$10, it will block invalid entries with Ignore blank on or off.

Data Validation on a Protected Sheet In Excel 2000 and earlier versions, you can change the selection in a data validation dropdown, if the list is from a range on the worksheet. If the list is typed in the data validation dialog box, the selection can't be changed. In Excel 2002 and later versions, neither type of dropdown list can be changed if the cell is locked and the sheet is protected. This MSKB article has information on the previous behaviour: XL97: Error When Using Validation Drop-Down List Box http://support.microsoft.com/default.aspx?id=157484

Make the Dropdown List Temporarily Wider The Data Validation dropdown is the width of the cell that it's in, to a minimum of about 3/4". You could use a SelectionChange event to temporarily widen the column when it's active, then make it narrower when you select a cell in another column. For example, with Data Validation cells in column D:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target.Column = 4 Then Target.Columns.ColumnWidth = 20 Else Columns(4).ColumnWidth = 5 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the column reference from 4 to match your worksheet.

Data Validation Font Size and List Length The font size in a data validation list can't be changed, nor can its default list length, which has a maximum of eight rows. If you reduce the zoom setting on a worksheet, it can be almost impossible to read the items in the dropdown list, as in the example at right. One workaround is to use programming, and a combo box from the Control Toolbox, to overlay the cell with data validation. If the user double-clicks on a data validation cell, the combobox appears, and they can choose from it. There are instructions here.

Make the Dropdown List Appear Larger In a Data Validation dropdown list, you can't change the font or font size. To make the text appear larger, you can use an event procedure (three examples are shown below) to increase the zoom setting when the cell is selected. (Note: this can be a bit jumpy) Or, you can use code to display a combobox, as described in the previous section. Zoom in when specific cell is selected If cell A2 has a data validation list, the following code will change the zoom setting to 120% when that cell is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$2" Then ActiveWindow.Zoom = 120 Else ActiveWindow.Zoom = 100 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the cell reference from $A$2 to match your worksheet.

Zoom in when specific cells are selected If several cells have a data validation list, the following code will change the zoom setting to 120% when any of those cells are selected. In this example, cells A1, B3 and D9 have data validation.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Intersect(Target, Range("A1,B3,D9")) Is Nothing Then ActiveWindow.Zoom = 100 Else ActiveWindow.Zoom = 120 End If End Sub

Zoom in when any cell with a data validation list is selected The following code will change the zoom setting to 120% when any cell with a data validation list is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim lZoom As Long Dim lZoomDV As Long Dim lDVType As Long lZoom = 100 lZoomDV = 120 lDVType = 0 Application.EnableEvents = False On Error Resume Next lDVType = Target.Validation.Type On Error GoTo errHandler If lDVType <> 3 Then With ActiveWindow If .Zoom <> lZoom Then .Zoom = lZoom End If End With Else With ActiveWindow If .Zoom <> lZoomDV Then .Zoom = lZoomDV End If

End With End If exitHandler: Application.EnableEvents = True Exit Sub errHandler: GoTo exitHandler End Sub

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Add Messages to Help the User


Input Message Error Alert Input Message You can display messages to give instructions to the people who use your spreadsheet. An Input Message can be displayed when the cell with data validation is selected. An Error Alert can be displayed if invalid data is entered. You can turn this off, to allow people to enter invalid data. For example, if the data validation cell contains a dropdown list, turn off the

Error Alert to allow users to type items that are not in the list.

Input Message a) Select the cells in which you want to apply data validation b) On the Settings tab, apply the required data validation (What is Data Validation?) c) Click on the Input Message tab to activate it d) Add a check mark to the Show input message when cell is selected box.

e) Type your message heading text in the Title box. This text will appear in bold print at the top of the message. f) Type your message in the Input message box. g) Click OK or follow the steps below to add an Error Alert. Error Alert a) Click on the Error Alert tab to activate it b) Add a check mark to the Show error alert after invalid data is entered box. c) Choose an Error Alert Style from the dropdown list. 1. Stop: This prevents the entry of invalid data. If the Retry button is clicked, the invalid entry is highlighted, and can be overtyped. If the Cancel button is clicked, the invalid entry is deleted, and the cell's original

content is restored. The user cannot leave the invalid entry in the cell

2. Warning: This discourages the entry of invalid data. If the Yes button is clicked, the invalid entry is accepted, and the next cell is selected. If the No button is clicked, the invalid entry is highlighted, and can be overtyped. If the Cancel button is clicked, the invalid entry is deleted, and the cell's original content is restored. The user can choose to leave the invalid entry in the cell. 3. Information: This announces the entry of invalid data. If the OK button is clicked, the invalid entry is accepted, and the next cell is selected. If the Cancel button is clicked, the invalid entry is deleted, and the cell's original content is restored. The user can choose to leave the invalid entry in the cell.

d) Type your message heading text in the Title box. This text will appear in bold print at the top of the message. f) Type your message in the Error message box. g) Click OK

Note: If the Office Assistant is visible, the Input Messages and Error Messages will be displayed as balloons

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Data Validation -- Tips and Quirks


Refer to a Source List on a Different Worksheet Use Dynamic Lists Data Validation Font Size and List Length Data Validation Dropdowns and Change Events Data Validation Dropdown Arrows Not Visible Invalid Entries are Allowed Data Validation on a Protected Sheet Make the Dropdown List Temporarily Wider Make the Dropdown List Appear Larger -- Zoom in when specific cell is selected -- Zoom in when specific cells are selected -- Zoom in when any cell with data validation is selected Refer to a Source List on a Different Worksheet When you try to create a data validation dropdown list, and refer to a source list on a different worksheet, you may see an error message: "You may not use references to other worksheets of workbooks for Data Validation criteria." To avoid this problem, name the list on the other worksheet, then refer to the named range, as described here: Data Validation If the list is in a different workbook, you can use the technique described here: Use a List from Another Workbook

Use Dynamic Lists Some lists change frequently, with items being added or removed. If the list is the source for a Data Validation dropdown, use a dynamic formula to name the range, and the dropdown list will be automatically updated. For instructions, view this page: Create a Dynamic Range Data Validation Dropdowns and Change Events In Excel 2000 and later versions, selecting an item from a Data Validation dropdown list will trigger a Change event. This means that code can automatically run after a user selects an item from the list. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList.zip file.

In Excel 97, selecting an item from a Data Validation dropdown list does not trigger a Change event, unless the list items have been typed in the Data Validation dialog box. In this version, you can add a button to the worksheet, and run the code by clicking the button. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97.zip file. Another option in Excel 97 is to use the Calculate event to run the code. To do this, refer to the cell with data validation in a formula on the worksheet, e.g. =MATCH(C3,CategoryList,0). Then, add the filter code to the worksheet's Calculate event. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97Calc.zip file.

Data Validation Dropdown Arrows Not Visible Occasionally, data validation dropdown arrows are not visible on the worksheet, in cells where you know that data validation lists have been created. The following are the most common reasons for missing arrows. Active Cell Only Only the active cell on a worksheet will display a data validation dropdown arrow. To mark cells that contain data validation lists, you can colour the cells, or add a comment. If you require visible arrows for all cells that contain lists, you can use combo boxes instead of data validation, and those arrows will be visible at all times. To create a combo box, choose View|Toolbars, and select either the Control Toolbox or the Forms toolbar. Hidden Objects If objects are hidden on the worksheet, the data validation dropdown arrows will also be hidden. To make objects visible, choose Tools|Options, and on the View tab, under Objects, select Show all. Dropdown Option In the Data Validation dialog box, you can turn off the option for a dropdown list. To turn it back on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, add a check mark to In-cell dropdown 4. Click OK

Freeze Panes In Excel 97, if a Data Validation dropdown list is in a frozen pane of the window, the dropdown arrow does not appear when the cell is selected. As a workaround, use Window|Split instead of Window|Freeze Panes This problem has been corrected in later versions.

Without frozen panes

Corruption If none of the above solutions explains the missing dropdown With frozen panes arrows, the worksheet may be corrupted. Try copying the data to a new worksheet or workbook, and the dropdown arrows may reappear. Or, try to repair the file as you open it: 1. 2. 3. 4. In Excel, choose File | Open Select the file with the missing data validation arrows On the Open button, click the arrow Click Open and Repair

5. When prompted, click Repair. Invalid Entries Are Allowed Although you have created data validation dropdown arrows on some cells, users may be able to type invalid entries. The following are the most common reasons for this. Error Alert If the Error Alert is turned off, users will be able to type any entry, without receiving an error message. To turn the alert on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Error Alert tab, add a check mark to the Show error alert after invalid data is entered box. 4. Click OK Blank Cells in Source List If the source list is a named range that contains blank cells, users may be able to type any entry, without receiving an error message. To turn prevent this: 1. Select the cell that contains a data

validation list 2. Choose Data|Validation 3. On the Settings tab, remove the check mark from the Ignore blank box. 4. Click OK Note: If the source list contains blank cells, and is a range address, e.g. $A$1:$A$10, it will block invalid entries with Ignore blank on or off. Data Validation on a Protected Sheet In Excel 2000 and earlier versions, you can change the selection in a data validation dropdown, if the list is from a range on the worksheet. If the list is typed in the data validation dialog box, the selection can't be changed. In Excel 2002 and later versions, neither type of dropdown list can be changed if the cell is locked and the sheet is protected. This MSKB article has information on the previous behaviour: XL97: Error When Using Validation Drop-Down List Box http://support.microsoft.com/default.aspx?id=157484

Make the Dropdown List Temporarily Wider The Data Validation dropdown is the width of the cell that it's in, to a minimum of about 3/4". You could use a SelectionChange event to temporarily widen the column when it's active, then make it narrower when you select a cell in another column. For example, with Data Validation cells in column D:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target.Column = 4 Then Target.Columns.ColumnWidth = 20 Else Columns(4).ColumnWidth = 5 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the column reference from 4 to match your worksheet.

Data Validation Font Size and List Length The font size in a data validation list can't be changed, nor can its default list length, which has a maximum of eight rows. If you reduce the zoom setting on a worksheet, it can be almost impossible to read the items in the dropdown list, as in the example at right. One workaround is to use programming, and a combo box from the Control Toolbox, to overlay the cell with data validation. If the user double-clicks on a data validation cell, the combobox appears, and they can choose from it. There are instructions here.

Make the Dropdown List Appear Larger In a Data Validation dropdown list, you can't change the font or font size. To make the text appear larger, you can use an event procedure (three examples are shown below) to increase the zoom setting when the cell is selected. (Note: this can be a bit jumpy) Or, you can use code to display a combobox, as described in the previous section. Zoom in when specific cell is selected If cell A2 has a data validation list, the following code will change the zoom setting to 120% when that cell is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$2" Then ActiveWindow.Zoom = 120 Else ActiveWindow.Zoom = 100 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the cell reference from $A$2 to match your worksheet.

Zoom in when specific cells are selected If several cells have a data validation list, the following code will change the zoom setting to 120% when any of those cells are selected. In this example, cells A1, B3 and D9 have data validation.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Intersect(Target, Range("A1,B3,D9")) Is Nothing Then ActiveWindow.Zoom = 100 Else ActiveWindow.Zoom = 120 End If End Sub

Zoom in when any cell with a data validation list is selected The following code will change the zoom setting to 120% when any cell with a data validation list is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim lZoom As Long Dim lZoomDV As Long Dim lDVType As Long lZoom = 100 lZoomDV = 120 lDVType = 0 Application.EnableEvents = False On Error Resume Next lDVType = Target.Validation.Type On Error GoTo errHandler If lDVType <> 3 Then With ActiveWindow If .Zoom <> lZoom Then .Zoom = lZoom End If End With Else With ActiveWindow If .Zoom <> lZoomDV Then .Zoom = lZoomDV End If

End With End If exitHandler: Application.EnableEvents = True Exit Sub errHandler: GoTo exitHandler End Sub

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples 8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Create an Order Form


Set up the Workbook Create the Product List Create a Data Validation Dropdown List Add the VLookup Formula Calculate the Row Total Total the Order Format the Order Form Add a Customer List In this order form, Data Validation is used to create a dropdown list of available products. In adjacent cells, VLookup formulas return the price of the selected products. Set up the Workbook Two worksheets are required in this workbook. 1. Delete all sheets except Sheet1 and Sheet2 2. Rename Sheet1 as Order Form 3. Rename Sheet2 as Products

Download the zipped sample file

Create the Product List 1. On the Products sheet, type the list of products and prices, as shown at right. 2. Select the list of products in cells A2:A6 3. Name the range ProductList (there are Naming instructions here: Name a Range) 4. Select the list of products and prices in cells A2:B6 5. Name the range ProductLookup.

Create a Data Validation Dropdown List The next step is to create the data validation dropdown lists, to make it easy to enter a product in the order form. There are detailed instructions here: Data Validation -- Introduction 1. 2. 3. 4. On the Order Form worksheet, select cells B5:B12 Choose Data | Validation From the Allow dropdown, choose List In the Source box, type: =ProductList

5. Click the OK button Add the VLookup Formula VLookup formulas in column C will return the price for each product selected in the order form. The VLookup formula is wrapped with an IF formula, to prevent errors if no product has been selected in a row. For more information on the VLookup formula, see Worksheet Functions -- VLookup 1. On the Order Form worksheet, select cells C5:C12 2. Type the formula: =IF(B5="","",VLOOKUP(B5,ProductLookup,2,FAL SE)) 3. Press Ctrl + Enter, to enter the formula in all the selected cells. Calculate the Row Total Quantity will be entered in column D, and the row total calculated in column E. The formula is wrapped with an IF formula, to prevent a zero calculation if no product has been selected in a row. 1. On the Order Form worksheet, select cells E5:E12 2. Type the formula: =IF(C5="","",C5*D5) 3. Press Ctrl + Enter, to enter the formula in all the selected

cells. Total the Order The SUM function is used to total all the rows in the Order Form. 1. On the Order Form worksheet, select cell E14 2. Type the formula: =SUM(E5:E12) 3. Press Enter, to complete the formula.

Format the Order Form Add cell borders and font formatting, to make the Order Form more attractive, and easy to use. 1. On the Order Form worksheet, add column headings in row 4, as shown at right. 2. Add the main heading, "Order Form", in cell B2 3. In cell C14, type "Total" 4. In cell E2, type the formula: =TODAY() 5. Select cells B4:E12, and add borders. 6. Add fill colour to columns B and D, where data entry is required. 7. Format the heading fonts as bold 8. Format the date as desired. Add a Customer List To enhance the order form, you can add a worksheet with customer names and addresses. Then, select a customer name on the order form, and have their address fill in automatically. Add the Customer List 1. Insert a new worksheet, and name it Customers 2. On the Customers sheet, in row 1, and the headings, Name, Street, City, Prov, PostalCode, DateEntered. 3. In the following rows, enter data for a few sample customers. 4. To name the customer list (for the dropdown list), select cell A2 5. Choose Insert | Name | Define 6. Type the name: CustList 7. In the Refers to box, type: =OFFSET(Customers!$A$2,0,0,COUNTA(Customers!

$A:$A)-1,1) 8. Click Add 9. To name the Customer lookup table (for the address lookup), type the name: CustLookup 10. In the Refers to box, type: =OFFSET(CustList,,,,6) 11. Click OK Create the Customer Dropdown and Lookup 1. 2. 3. 4. On the Order Form worksheet, select rows 3:7 Choose Insert | Rows In cell B4, type: Ship to: In cell B5, add a Data Validation list, with CustList as the source 5. Select cells B6:E6, and choose Format | Cells 6. On the Alignment tab, add a check mark to the Merge Cells box, click OK 7. Select cells B7:E7, and press the F4 key, to repeat the previous formatting 8. In cell B6, type the formula: =IF(B5="","",VLOOKUP(B5,CustLookup,2,FALSE) ) 9. In cell B7, type the formula that will lookup city, province, and postal code: =IF(B5="","",VLOOKUP(B5,CustLookup,3,FALSE) &", " &VLOOKUP(B5,CustLookup,4,FALSE)&" " &VLOOKUP(B5,CustLookup,5,FALSE)) 10. To test the formulas, select a customer from the dropdown list in cell B5, and the address should appear in B6 and B7.
Download the zipped sample file

Excel -- Data Validation -- Tips and Quirks


Refer to a Source List on a Different Worksheet Use Dynamic Lists Data Validation Font Size and List Length Data Validation Dropdowns and Change Events Data Validation Dropdown Arrows Not Visible Invalid Entries are Allowed Data Validation on a Protected Sheet Make the Dropdown List Temporarily Wider Make the Dropdown List Appear Larger -- Zoom in when specific cell is selected -- Zoom in when specific cells are selected -- Zoom in when any cell with data validation is selected Refer to a Source List on a Different Worksheet When you try to create a data validation dropdown list, and refer to a source list on a different worksheet, you may see an error message: "You may not use references to other worksheets of workbooks for Data Validation criteria." To avoid this problem, name the list on the other worksheet, then refer to the named range, as described here: Data Validation If the list is in a different workbook, you can use the technique described here: Use a List from Another Workbook

Use Dynamic Lists Some lists change frequently, with items being added or removed. If the list is the source for a Data Validation dropdown, use a dynamic formula to name the range, and the dropdown list will be automatically updated. For instructions, view this page: Create a Dynamic Range

Data Validation Dropdowns and Change Events In Excel 2000 and later versions, selecting an item from a Data Validation dropdown list will trigger a Change event. This means that code can automatically run after a user selects an item from the list. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList.zip file. In Excel 97, selecting an item from a Data Validation dropdown list does not trigger a Change event, unless the list items have been typed in the Data Validation dialog box. In this version, you can add a button to the worksheet, and run the code by clicking the button. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97.zip file. Another option in Excel 97 is to use the Calculate event to run the code. To do this, refer to the cell with data validation in a formula on the worksheet, e.g. =MATCH(C3,CategoryList,0). Then, add the filter code to the worksheet's Calculate event. To see an example, go to the Sample Worksheets page, and under the Filters heading, find Product List by Category, and download the ProductsList97Calc.zip file.

Data Validation Dropdown Arrows Not Visible Occasionally, data validation dropdown arrows are not visible on the worksheet, in cells where you know that data validation lists have been created. The following are the most common reasons for missing arrows. Active Cell Only Only the active cell on a worksheet will display a data validation dropdown arrow. To mark cells that contain data validation lists, you can colour the cells, or add a comment. If you require visible arrows for all cells that contain lists, you can use combo boxes instead of data validation, and those arrows will be visible at all times. To create a combo box, choose View|Toolbars, and select either the Control Toolbox or the Forms toolbar. Hidden Objects If objects are hidden on the worksheet, the data validation dropdown arrows will also be hidden. To make objects visible, choose Tools|Options, and on the View tab, under Objects, select Show all.

Dropdown Option In the Data Validation dialog box, you can turn off the option for a dropdown list. To turn it back on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, add a check mark to In-cell dropdown 4. Click OK Freeze Panes In Excel 97, if a Data Validation dropdown list is in a frozen pane of the window, the dropdown arrow does not appear when the cell is selected. As a workaround, use Window|Split instead of Window|Freeze Panes This problem has been corrected in later versions.

Without frozen panes

Corruption If none of the above solutions explains the missing dropdown With frozen panes arrows, the worksheet may be corrupted. Try copying the data to a new worksheet or workbook, and the dropdown arrows may reappear. Or, try to repair the file as you open it: 1. 2. 3. 4. In Excel, choose File | Open Select the file with the missing data validation arrows On the Open button, click the arrow Click Open and Repair

5. When prompted, click Repair. Invalid Entries Are Allowed Although you have created data validation dropdown arrows on some cells, users may be able to type invalid entries. The following are the most common reasons for this. Error Alert If the Error Alert is turned off, users will be able to type any entry, without receiving an error message. To turn the alert on: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Error Alert tab, add a check mark to the Show error alert after invalid data is entered box.

4. Click OK Blank Cells in Source List If the source list is a named range that contains blank cells, users may be able to type any entry, without receiving an error message. To turn prevent this: 1. Select the cell that contains a data validation list 2. Choose Data|Validation 3. On the Settings tab, remove the check mark from the Ignore blank box. 4. Click OK Note: If the source list contains blank cells, and is a range address, e.g. $A$1:$A$10, it will block invalid entries with Ignore blank on or off. Data Validation on a Protected Sheet In Excel 2000 and earlier versions, you can change the selection in a data validation dropdown, if the list is from a range on the worksheet. If the list is typed in the data validation dialog box, the selection can't be changed. In Excel 2002 and later versions, neither type of dropdown list can be changed if the cell is locked and the sheet is protected. This MSKB article has information on the previous behaviour: XL97: Error When Using Validation Drop-Down List Box http://support.microsoft.com/default.aspx?id=157484

Make the Dropdown List Temporarily Wider The Data Validation dropdown is the width of the cell that it's in, to a minimum of about 3/4". You could use a SelectionChange event to temporarily widen the column when it's active, then make it narrower when you select a cell in another column. For example, with Data Validation cells in column D:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Target.Column = 4 Then Target.Columns.ColumnWidth = 20 Else Columns(4).ColumnWidth = 5 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the column reference from 4 to match your worksheet. Data Validation Font Size and List Length The font size in a data validation list can't be changed, nor can its default list length, which has a maximum of eight rows. If you reduce the zoom setting on a worksheet, it can be almost impossible to read the items in the dropdown list, as in the example at right. One workaround is to use programming, and a combo box from the Control Toolbox, to overlay the cell with data validation. If the user double-clicks on a data validation cell, the combobox appears, and they can choose from it. There are instructions here.

Make the Dropdown List Appear Larger In a Data Validation dropdown list, you can't change the font or font size. To make the text appear larger, you can use an event procedure (three examples are shown below) to increase the zoom setting when the cell is selected. (Note: this can be a bit jumpy) Or, you can use code to display a combobox, as described in the previous section. Zoom in when specific cell is selected If cell A2 has a data validation list, the following code will change the zoom setting to 120% when that cell is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Address = "$A$2" Then ActiveWindow.Zoom = 120 Else ActiveWindow.Zoom = 100 End If End Sub

To add this code to the worksheet: 1. Right-click on the sheet tab, and choose View Code. 2. Copy the code, and paste it onto the code module. 3. Change the cell reference from $A$2 to match your worksheet.

Zoom in when specific cells are selected If several cells have a data validation list, the following code will change the zoom setting to 120% when any of those cells are selected. In this example, cells A1, B3 and D9 have data validation.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Intersect(Target, Range("A1,B3,D9")) Is Nothing Then ActiveWindow.Zoom = 100 Else ActiveWindow.Zoom = 120 End If End Sub

Zoom in when any cell with a data validation list is selected The following code will change the zoom setting to 120% when any cell with a data validation list is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim lZoom As Long Dim lZoomDV As Long Dim lDVType As Long lZoom = 100 lZoomDV = 120 lDVType = 0 Application.EnableEvents = False On Error Resume Next lDVType = Target.Validation.Type On Error GoTo errHandler If lDVType <> 3 Then With ActiveWindow If .Zoom <> lZoom Then .Zoom = lZoom End If End With Else With ActiveWindow If .Zoom <> lZoomDV Then .Zoom = lZoomDV End If End With End If exitHandler: Application.EnableEvents = True Exit Sub errHandler: GoTo exitHandler End Sub

1. Data Validation 2. Data Validation -- Create Dependent Lists 3. Hide Previously Used Items in a Dropdown List 4. Display Messages to the User 5. Use a List from Another Workbook 6. Validation Criteria Examples 7. Custom Validation Criteria Examples

8. Data Validation Tips 9. Data Validation Documentation 10 Data Validation -- Combo box 11. Data Validation -- Combo Box - Named Ranges 12. Data Validation -- Display Input Messages in a Text Box 13. Data Validation -- Dependent Dropdowns from a Sorted List

Excel -- Names -- Naming Ranges


Name a Range -- Name Box Create a Dynamic Range Name a Range - Name Box 1. 2. 3. 4. Select the cell(s) to be named Click in the Name box, to the left of the formula bar Type a one-word name for the list, e.g. FruitList. Press the Enter key.

After naming the range, you can select its name in the Name Box dropdown list, to select the range on the worksheet. You can also use names in formulas. For example: =SUM(JanSales) =TotalSales * TaxRate To view the steps in a short video, click here.

Create a Dynamic Range You can use a dynamic formula to define a range. As new items are added, the range will automatically expand. Note: Dynamic named ranges will not appear in the Name Box dropdown list. However, you can type the name in the Name Box, to select the range on the worksheet.

1. Choose Insert>Name>Define 2. Type a name for the range, e.g. NameList

3. In the Refers To box, enter an Offset formula that defines the range size, based on the number of items in the column, e.g.: =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),1) In this example, the list is on Sheet1, starting in cell A1 The arguments used in this Offset function are: 1. Reference cell: Sheet1!$A$1 2. Rows to offset: 0 3. Columns to offset: 0 4. Number of Rows: COUNTA(Sheet1!$A:$A) 5. Number of Columns: 1 Note: for a dynamic number of columns, replace the 1 with: COUNTA(Sheet1!$1:$1) 4. Click OK 1. Names -- Naming Ranges 2. Names -- Using Names in Formulas

Excel -- Filters -- Advanced Filters --

Introduction
1. Advanced Filters--Introduction a) Apply an Advanced Filter b) Filter Unique Records c) Extract Data to Another Worksheet d) Setting up the Criteria Range e) Using Wildcards in Criteria f) Criteria Examples 2. Advanced Filters -- Complex Criteria Apply an Advanced Filter 1. Set up the database 1. The first row (A1:D1) has headings. 2. Subsequent rows contain data. 3. There are no blank rows within the database. 4. There is a blank row at the end of the database, and a blank column at the right. 2. Set up the Criteria Range (optional) In the criteria range, you can set the rules for the data that should remain visible after the filter is applied. You can use one criterion, or several. 1. In this example, cells F1:F2 are the criteria range. 2. The heading in F1 exactly matches a heading (D1) in the database. 3. Cell F2 contains the criterion. The > (greater than) operator is used, with the number 500 (no $ sign is included).. After the filter is applied, orders with a total greater than $500 will remain visible. Other operators include: < less than <= less than or equal to >= greater than or equal to <> not equal to
For a zipped workbook with sample data and criteria, click here.

3. Set up the Extract Range (optional) If you plan to copy the data to another location, you can specify the columns that you want to extract. If you want to extract ALL columns, you can leave the extract range empty. 1. Select the cell at the top left of the range for the extracted data. 2. Type the headings for the columns that you want to extract. These must be an exact match for the column headings, in spelling and punctuation. The column order can be different, and any or all of columns can be included. 4. Apply the Filter 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter. (In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. You can choose to filter the list in place, or copy the results to another location. 4. Excel should automatically detect the list range. If not, you can select the cells on the worksheet. 5. Select the criteria range on the worksheet 6. If you are copying to a new location, select a starting cell for the copy Note: If you copy to another location, all cells below the extract range will be cleared when the Advanced Filter is applied. 7. Click OK

Filter Unique Records You can use an Advanced Filter to extract a list of unique items in the database. For example, get a list of customers from an order list, or compile a list of products sold: Note: The list must contain a heading, or the first item may be duplicated in the results. 1. Select a cell in the database. 2. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 3. Choose 'Copy to another location'. 4. For the List range, select the column(s) from which you want to extract the unique values. 5. Leave the Criteria Range blank. 6. Select a starting cell for the Copy to location. 7. Add a check mark to the Unique records only box.

8. Click OK. Watch the Video View the steps described above, in a short video clip. Excel 2007 video

Extract Data to Another Worksheet If the database is on Sheet1 and you would like to extract data to Sheet2: 1. Go to Sheet 2 2. Select a cell in an unused part of the sheet (cell C4 in this example). 3. From the Data menu, choose Filter, Advanced Filter.(In Excel 2007, click the Data tab on the Ribbon, then click Advanced Filter.) 4. Choose Copy to another location. 5. Click in the List Range box 6. Select Sheet 1, and select the database. 7. (optional) Click in the Criteria range box. 8. Select the criteria range 9. Click in the Copy to box. 10. Select the cell on Sheet 2 in which you want the results to start, or select the headings that you have typed on Sheet 2. 11. (optional) Check the box for Unique Values Only 12. Click OK Setting up the Criteria Range AND vs OR If a record meets all criteria on one row in the criteria area, it will pass through the filter. In example 1, at right -customer must be MegaMart AND product must be Cookies 1. AND total must be greater than 500. Criteria on different rows are joined with an OR operator. In the second example at right -customer must be MegaMart OR product must be Cookies OR total must be greater than 500. 2. By using multiple rows, you can combine the AND and OR operators. In the third example at right -customer must be MegaMart AND product must be Cookies OR product must be Cookies AND total must be greater than 500. 3.

Using Wildcards in Criteria Use wildcard characters to filter for a text string in a cell. The * wildcard The asterisk (*) wildcard character represents any number of characters in that position, including zero characters. In this example, any customer whose name contains "mart" will pass through the filter. The ? wildcard The question mark (?) wildcard character represents one characters in that position. In this example any 4-letter product that begins with c, and ends with ke, will pass through the filter. The ~ wildcard The tilde (~) wildcard character lets you search for characters that are used as wildcards. In this example any products that begins with Good and ends with Eats, will pass through the filter. To find only the product named Good*Eats, use a tilde character in front of the asterisk.

Criteria Examples
Extract Items in a Range

To extract a list of items in a range, you can use two columns for one of the fields (e.g. Date). If you enter two criteria on the same row in the criteria range, you create an AND statement. In this example, any records that are extracted must be greater than the first date AND less than the second date.

Create Two or More Sets of Conditions

If you enter criteria on different rows in the criteria range, you create an OR statement. In this example, extracted records must meet both conditions in row 2 OR both conditions in row 3.

Extract Items with Specific Text

When you use text as criteria with an advanced filter, Excel finds all items that begin with that text. For example, if you type "Ice" as a criterion, Excel finds "Ice", "Ice Cream" and "Ice Milk" To extract only the records for Ice, use the following format: ="=Ice"

Excel -- Filters -- AutoFilter Basics


Use AutoFilter to hide some of the data in your worksheet. For example, you can focus on sales of a specific product, or print a list of your largest orders. Prepare the Database Filter the Database Remove a Filter Create a Custom Filter Prepare the Database 1. Set up the database a) The first row (A1:G1) has headings. b) Subsequent rows contain data. c) There are no blank rows within the database. d) There is a blank row at the end of the database, and a blank column at the right. 2. Turn on AutoFilter a) Select a cell in the database. b) From the Data menu, choose Filter, AutoFilter. A dropdown arrow appears beside each column heading.
For a zipped workbook with sample data, click here.

Filter the Database To filter the list, for example to view orders for one Product, choose a criterion from one of the dropdown lists. To further filter the list, choose from another column's dropdown list, e.g. Customer. Rows that don't meet the criteria will be hidden. Rows that remain visible have a blue number in the row button. The dropdown arrow for column(s) in which a criterion has been applied will also be blue. Remove a Filter To remove the filter, and leave AutoFilter turned on: In each column in which a filter has been applied, choose (All), the first item in the dropdown list OR From the Data menu, choose Filter, Show All To remove the current filter, and turn off AutoFilter: From the Data menu, choose Filter, AutoFilter Special Filters Blank Cells in a Column If there are any blank cells in the column, the drop down list will contain two additional items -- (Blanks) and (NonBlanks). Filter Highest and Lowest Numbers To find the highest or lowest numbers in the table, choose (Top 10...) from the number column dropdown. 1. In the first box, choose Top or Bottom. 2. In the middle box, enter a number. 3. In the third box, choose Items or Percent. Note: The results are the highest or lowest values for the entire list, not the currently filtered list. If other columns are also filtered, you may see fewer than the specified number of items.

Create a Custom Filter When you choose a criterion from a dropdown list, the list is filtered for rows that are equal to the criterion. If you need more options while filtering, you can choose (Custom...) from the dropdown list. This opens the Custom AutoFilter dialog box. To filter for one criterion: a) From the first dropdown list, select an operator. b) In the text box, type a value. c) Click OK.

To filter for two criteria: a) From the first dropdown list, select an operator. b) In the text box, type a value. c) Choose And or Or d) From the second dropdown list, select an operator. e) In the text box, type a value. f) Click OK.

Answers to Frequently Asked Questions about Microsoft Excel

Worksheet Functions and Formats


1. Functions 1. Is there a formula that will round a value to the nearest increment of 5? 2. What formula will look at a cell, find that value in another sheet and return data from an adjacent 3. 4. 5. 6. 7. 8.
column. I want to add the largest/smallest 5 entries in A column. How do I pick 20 random items from a list of 100? Is it possible to write a SUMIF worksheet formula to sum visible cells only? How do I enter two criteria so I can sum numbers between 5 and 10? Why does my function display #NAME? Is there a way of returning the name of a sheet in a cell without using code?

2. Calculation 1. My spreadsheet does not calculate correctly ! I'm right, Excel's wrong! 2. My spreadsheet does not calculate at all! 3. The formulas are showing, instead of the results 3. Working with Tables and Lists 1. I have data stored in rows and I want to change these rows to columns 2. Using Data>Subtotals, I would like to create a table with just these subtotals, not the detail rows. 3. When I use AutoFilter I don't see all the items in the drop down list. Why not? 4. In a cell I have "lastname, firstname". I want lastname in one cell and first name in another. 5. I want to fix a cell so the user can only choose from a list

4. Formatting 1. Is there a way to make a cell turn red, based on the value in another cell? 2. Can I format a cell to blink or flash when a condition is met? 3. How can I add a bar above a character, e.g. 5. International issues 1. Translate Functions 1. Functions
Is there a formula that will round a value to the nearest increment of 5? ?

=ROUND(A1/5,0)*5
or to the nearest quarter ?

=ROUND(A1/0.25,0)*0.25
I am looking for a formula that will look at an adjacent column then find that value in another sheet and return the data from an adjacent column.

=VLOOKUP(A2,Sheet2!A2:B100,2,FALSE) For more information and examples, see Excel -- Worksheet Functions -- VLookup
I want to add the largest/smallest 5 entries in A column.

=SUM(LARGE(A:A,{1,2,3,4,5}))
How do I pick 20 random items from a list of 100?

Enter the items down A1:A100. In B1:B100 enter formula =RAND(). Sort the list by B column; top 20 rows is your selection. Press F9 for new B numbers and repeat for a new selection.
Is it possible to write a SUMIF worksheet formula to sum visible cells only?

If the cells are hidden as a result of AutoFiltering, you can use the SUBTOTAL function, with 9 as the first argument
I can sum all numbers >=10 with =SUMIF(A1:A20,">=10") . But how do I enter two criteria so I can sum numbers between 5 and 10?

That equals sum of all >=5 minus sum of all > 10: =SUMIF(A1:A20,">=5")-SUMIF(A1:A20,">10") Or you can use this method: =SUMPRODUCT((A1:A20>=5)*(A1:A20<=10)*A1:A20)
Why does my function display #NAME?

The function may point to an add-in function that is not available to this Excel. Most frequently it's an Analysis ToolPak function; choose Tools > Add-Ins and check that there are checks against Analysis ToolPak. Unlike Excel's built-in functions, Add-in functions do not translate themselves to regional language, so American add-in functions are by default unavailable on a Norwegian computer and vice versa.
Is there a way of returning the name of a sheet in a cell without using code?

=CELL("Filename",A1) returns the complete file path and sheet name

=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255) will strip away everything but the sheet name. Note: The file must be saved or the formula will not work. 2. Calculation
My spreadsheet does not calculate correctly ! I'm right, Excel's wrong!

There are three common causes for messages like this. 1. What is displayed in the cells is not what's really there. A cell can show 1 (no decimals format) but it may contain real or calculated values like 0.6 or 1.4. Add or multiply a bunch of those and you're surprised; Excel will calculate with real cell contents, NOT displayed contents. You may choose "precision as displayed" in the Tools > Options menu for a workaround, but make sure you know what you're doing. 2. A computer use binary numbers, and this has its limitations. It canot represent numbers like 1/10 exactly. Numbers like that are rounded to nearest 15 significant decimal digits, and Excel will be "wrong" around 15th-16th digit. Some operations suffer from this, and some Boolean tests (tests that may appear as 0.1=0.1) can return False because of this. "Normal work" like sensible-number budgeting and day-to-day math is usually not affected, but this may not be the tool for advanced science. 3. You are using Excel's statistical functions. Some of those are not good enough. LINEST() (also SLOPE(), INTERCEPT(), VAR(), STDEV(), LOGEST(), TREND(), FORECAST(), etc.) uses a numerically unstable algorithm. You're right, Excel's wrong. Links to backgrounders and tools at http://www.mathtools.net/Excel/Statistics/index.html
My spreadsheet does not calculate at all!

1. Perhaps Calculation is set to Manual, alter this in Tools > Options menu.
The formulas are showing, instead of the results!

1. The cell may be formatted as Text. To change it, choose Format>Cells, and on the Number tab, choose a category other than Text, e.g. General or Number. 2. Perhaps the View Formulas option is turned on. To turn it off, choose Tools>Options. On the View tab, remove the check mark from Formulas.

Tip: The keyboard shortcut to show or hide the formulas is Ctrl + ` (accent grave, may be above the Tab key on the keyboard) 3. Working with Tables and Lists
I have data stored in rows and I want to change these rows to columns

Select the data, copy it, select where you want it, choose Edit>Paste Special, check the Transpose option, click OK

Using Data>Subtotals, I would like to create a table that has just these subtotals, not the hidden detail rows.

1. Once you've applied the Subtotal, collapse the outline so that only the rows you want to copy are visible. 2. Select the cells. 3. Choose Edit>Go To, click the Special button 4. Select 'Visible Cells Only', click OK 5. Click the Copy button 6. Go to another sheet, and paste
When I use AutoFilter I don't see all the items in the drop down list. Why not?

An AutoFilter dropdown list will only show 1000 entries. You could add a new column, and use a formula to split the list into 2 or three groups, e.g.: =IF(LEFT(C2,1)<"N","A-M","N-Z") Filter on this column first, then by the intended criteria. Another option is to choose Custom from the drop-down list, and type the criteria.
In a cell I have "LastName, FirstName". I want to put Last Name in one cell and Ffirst Name in another.

Use Data>Text to Columns and specify the comma as a delimiter.


I want to fix a cell so the user can only choose from a list, for example DHL, FEDEX or UPS.

1. Select the region you want to apply this to, then choose Data>Validation. 2. In the Allow dropdown, select List. 3. In the Source textbox, enter "DHL,FEDEX,UPS" (without the quotes)

4. Formatting
Is there a way to create a formula that will do this type of function -=IF(D25 does not equal E25 then D25 font will turn red)?

Try Conditional Formatting: 1. Select cell D25. 2. Choose Format>Conditional Formatting.

3. Set Condition 1 - Cell Value Is, not equal to, click on E25 on the worksheet. 4. Click on Format, select the Font tab. Under Colour, choose red. 5. Click OK, OK.

Can I format a cell blink or flash when a condition is met?

No.
How can I add a bar above a character, e.g. ?

1. Before you type the character for which you want the overbar, change the font to Symbol. 2. To create the bar, type the ` character (accent grave, may be above the Tab key) 3. Then, stay in Symbol font, or switch to a different font, and type the character that has the overbar. Note: This technique looks better on-screen in some font sizes than in others, but all should look okay when printed. 5. International Issues
Translate Functions

These functions are in English, and you can not enter them in a Swedish Excel as is. Run this macro:
Sub EnterEnglishFunction() ActiveCell.Formula = InputBox("English function:") End Sub

paste the function in and OK, and in most cases it translates.

Excel Functions
These files were created by Microsoft Excel MVP Norman Harker, an Australian academic specialising in real estate appraisal, investment analysis and real estate financial feasibility studies. The files are provided "AS IS" with no warranties. They can be freely distributed and used without a licence, but may not be sold, or included as part of any other product without the written permission of Norman Harker & Associates.

Excel Functions -- a zipped Excel workbook that contains: -- All Functions Sheet with Name, Source, Description, Syntax -- Classified functions Sheets with Name, Source, Description, Syntax and separate listing of all arguments with descriptions for that classification. -- All Arguments Sheet -- All Excel Arguments and Descriptions Apx01FuncList.zip 80 kb -- Version with buttons that open applicable Excel Help page, for Excel 2000 or higher available by email request to Norman Harker & Associates or click here to download FuncRefXLv4-0.zip 301 kb Excel Functions -- a zipped Word document that contains a few notes on special items such as Rounding and Counting functions. Hard Copy of Excel File in Table form (Except for All Arguments sheet). FuncRefWdV4-0.zip 156 kb ISO Week Number -- Excel add-in which contains a User-Defined function to calculate the ISOcompliant week number. ISOWEEKNUMNH.zip 9 kb

Excel -- Worksheet Functions -- Count Cells


Count Cells with Numbers-- COUNT Count Cells with Data-- COUNTA Count Blank Cells -- COUNTBLANK Count cells that match criteria -- COUNTIF - Match criterion exactly - Match criterion in a string - Match criterion using operator - Match criteria in a range Count cells that match multiple criteria -- SUMPRODUCT Count the Numbers in a Filtered List -- SUBTOTAL Count Specific Items in a Filtered List Count Visible Items in a Filtered List Count Cells with Numbers -- COUNT The COUNT function will count cells that contain numbers. Its syntax is: =COUNT(value1, value2,...value30). The arguments (e.g. value1) can be cell references, or values typed into the formula. The following example uses one argument -- a reference to cells A1:A5. 1. Enter the sample data on your worksheet 2. In cell A7, enter a COUNT formula, to count the numbers in column A: =COUNT(A1:A5) 3. Press the Enter key, to complete the formula. 4. The result will be 3, the number of cells that contain numbers. Cell A1 isn't counted, because it contains text. Note: Since dates are stored as numbers, COUNT will include any cells that contain dates. Download zipped sample workbook

=COUNT(A1:A5)

Count Cells with Data -- COUNTA The COUNTA function will count cells that are not empty. Its syntax is: =COUNTA(value1, value2,...value30). The arguments (e.g. value1) can be cell references, or values typed into the formula. The following example uses one argument -- a reference to cells A1:A5. 1. Enter the sample data on your worksheet 2. In cell A7, enter a COUNTA formula, to count the numbers in column A: =COUNTA(A1:A5) 3. Press the Enter key, to complete the formula. 4. The result will be 4, the number of cells that contain data. Note: COUNTA will count cells with formulas including those that look empty, because they evaluate to "", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but then were converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank" converted cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys." Count Blank Cells -- COUNTBLANK The COUNTBLANK function will count cells that are empty. Its syntax is: =COUNTBLANK(range). The following example uses a reference to cells A1:A5. 1. Enter the sample data on your worksheet 2. In cell A7, enter a COUNTBLANK formula, to count the numbers in column A: =COUNTBLANK(A1:A5) 3. Press the Enter key, to complete the formula. 4. The result will be 1, the number of empty cells. Note: COUNTBLANK will count cells with formulas including those that look empty, because they evaluate to "", e.g. =IF(B2="","",B2). It will also count cells which had formulas that evaluated to "", but then were converted to values (Edit | Paste Special, Values). You can see apostrophes in those "non-blank" converted cells, if you add a check mark to Tools | Options, Transition tab, "Transition navigation keys." =COUNTA(A1:A5)

=COUNTBLANK(A1:A5)

Count cells that match criteria -- COUNTIF Match criterion exactly You can count cells that meet a specific criterion. In this example only the Pen orders will be counted. 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: COUNTIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes: "Pen" Note: upper and lower case are treated equally 7. Type a closing bracket The completed formula is: =COUNTIF(A1:A10,"Pen") 8. Press the Enter key to complete the entry 9. The result will be 4, the number of cells that contain "Pen"

Match criterion in a string You can count cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be counted, because they contain the string "pen". 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: COUNTIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A1:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters: "*Pen*" Note: upper and lower case are treated equally 7. Type a closing bracket The completed formula is: =COUNTIF(A1:A10,"*Pen*") 8. Press the Enter key to complete the entry 9. The result will be 6, the number of cells that contain the string, "Pen" Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 7 above could be changed to: =COUNTIF(A1:A10,"*" & B12 & "*") if cell B12 contained the text pen.

Criterion and operator You can use an operator with a criterion. In this example only the rows where the quantity is greater than or equal to ten will be counted. 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: COUNTIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells B1:B10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for rows where the quantity is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes: ">=10" Note: Even though this is a numerical criterion, it must enclosed in double quote marks. 7. Type a closing bracket 8. The completed formula is: =COUNTIF(B1:B10,">=10") 9. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8 above could be changed to: =COUNTIF(B1:B10,">=" & B12) if cell B12 contained the number 10. Or, you could use a function as part of the criterion. For example: =COUNTIF(A1:A10,"<"&TODAY())

Match criteria in a range You can combine COUNTIF formulas, to count rows that are within a range of values. In this example, the formula will count rows where the quantity is between 5 and 10 (inclusive). 1. Select the cell in which you want to see the count (cell A12 in this example) 2. Type a formula to count rows greater than or equal to 5: =COUNTIF(B1:B10,">=5") 3. Type a minus sign 4. Type a formula to count rows greater than 10: COUNTIF(B1:B10,">10") 5. The completed formula is: =COUNTIF(B1:B10,">=5")COUNTIF(B1:B10,">10") 6. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 8 above could be changed to: =COUNTIF(B1:B10,">=" & B12) COUNTIF(B1:B10,">" & C12) if cell B12 contained the number 5 and cell C12 contained the number 10.

Count cells that match multiple criteria -SUMPRODUCT Match multiple criteria You can count rows that meet two or more criteria. In this example only the rows where the item is "Pen" and the quantity is greater than or equal to ten will be counted. 1. Select the cell in which you want to see the total 2. Type an equal sign (=) to start the formula 3. Type: SUMPRODUCT(--( 4. Select the cells that contain the values to check for the first criterion. In this example, cells A2:A10 will be checked 5. Type the first criterion: ="Pen" Note: Because this is a text criterion, it is enclosed in double quote marks. 6. Type ),--( 7. Select the cells that contain the values to check for the second

criterion. In this example, cells B2:B10 will be checked 8. Type the second criterion: >=10 Note: Because this is a numerical criterion, it isn't enclosed in double quote marks. 9. Finish with closing brackets: )) 10. The completed formula is shown at right. 11. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell, as shown in the second formula at right

Use typed criteria: =SUMPRODUCT(--(A2:A10="Pen"),--(B2:B10>=10)) or cell references: =SUMPRODUCT(--(A2:A10=D2),--(B2:B10>=E2))

Count Rows in a Filtered List -- SUBTOTAL After you filter the rows in a list, you can use the SUBTOTAL function to count the visible rows. 1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics 2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders. 3. Select the cell immediately below the column you want to sum. 4. Click the AutoSum button on the Excel's Standard toolbar. o If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button. 5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column o The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. The default is 9, which tells Excel to SUM the numbers. o Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list. 6. To Count all the non-empty cells in column D, use a 3 as the first argument: =SUBTOTAL(3,D2:D10) 7. Press the Enter key to complete the formula entry. Note: In Excel 2003, you can use the formula:

=SUBTOTAL(3,D2:D10)

=SUBTOTAL(103,D2:D10) Count Visible Items in a Filtered List Laurent Longre created a formula that lets you work with visible rows after a filter. For information see, Power Formula Technique in this article at John Walkenbach's web site: http://j-walk.com/ss/excel/eee/eee001.txt Incorporating that technique, SUMPRODUCT can be used to count visible items in a filtered table. In the following example, column D has been filtered for amounts greater than 100. The following formula will count the number of visible rows that contain "Pen" in column A. 1. From the dropdown list in cell D1, select Custom. 2. Filter for rows greater than 100. 3. In cell A12, type: Pen 4. In cell B12, enter the following formula: =SUMPRODUCT(SUBTOTAL(3,OFFSET(A1:A10,ROW(A1:A10) -MIN(ROW(A1:A10)),,1)), --(A1:A10=A12)) 5. Press the Enter key to complete the formula entry. Download zipped sample workbook Worksheet Functions -- Sum Cells Worksheet Functions -- VLOOKUP Worksheet Functions -- INDEX / MATCH Worksheet Functions -- Count Cells Worksheet Functions -- INDIRECT

Excel -- Worksheet Functions -- INDEX / MATCH


INDEX Function -- Arguments INDEX Function -- Example MATCH Function -- Arguments MATCH Function -- Example INDEX/MATCH Function -- Example INDEX/MATCH Function -- Example 2 INDEX/MATCH Function -- Example 3 INDEX/MATCH Function -- Example 4 Troubleshoot the MATCH function The INDEX function can return an item from a specific position in a list. The MATCH function can return the position of a value in a list. Download zipped sample workbook

The INDEX and MATCH functions can be used together, as a flexible and powerful tool for extracting data from a table.

Small Med Large 1 12 15 2 Sweater 10 The INDEX function has three arguments: 35 40 3 Jacket 30 25 30 35 4 Pants 5 Item Price 6 Size 1. array: Where is the list? If you use an absolute reference Med Pants ? ($A$2:$B$4), instead of a relative reference (A2:B4), it will 7 be easier to copy to formula to other cells. Or, name the lookup table, and refer to it by name. 2. row_num: Which row has the value you want returned? In this example, the item in the third row will be returned.

INDEX Function -- Arguments

3. [column_num]: Which column has the value you want returned? In this example, the item in the second column will be returned. INDEX Function -- Example The INDEX function can return an item from a specific position in a specific column in a list. For example, what is the 3rd item in the 2nd column in the list at right? 1. Select the cell in which you want the result 2. Type an equal sign, the INDEX function name, and an opening parenthesis: =INDEX( 3. Select the cells that contain the list -- cells A2:B4 in this example 4. Press the F4 key on the keyboard, to change the reference to an absolute reference: $A$2:$B$4. Then, if you copy the formula to another cell, it will continue to refer to the list of items. 5. Type a comma, to separate the arguments 6. Type the number of the item you want to return -- 3 in this example 7. Type a comma, to separate the arguments 8. Type the number of the column you want to return -- 2 in this example 9. Finish with a closing parenthesis. The completed formula is: =INDEX($A$2:$B$4,3,2) 10. Press the Enter key to see the result.
A 1 2 3 4 5 Item Sweater Jacket Pants B Price 10 30 25

=INDEX($A$2:$B$4,3,2)

MATCH Function -- Arguments The MATCH function has three arguments:

1. lookup_value: What value do you want to find in the list? You can type the value, or refer to a cell that contains the value. 2. lookup_array: Where is the list? 3. [match_type]: Match_type can be -1, 0, or 1. It tells Excel how to match the lookup_value to values in the lookup_array. 1 -- find the largest value less than or equal to lookup_value (the list must be in ascending order) 0 -- find the first value exactly equal to lookup_value. Lookup_array (the list can be in any order) -1 -- find the smallest value greater than or equal to lookup_value. (the list must be in descending order) Note: If match_type is omitted, it is assumed to be 1. MATCH Function -- Example The MATCH function can find a value in a list, and return its position. For example, where is "Jacket" in the list at right? 1. Select the cell in which you want the result 2. Type an equal sign, the MATCH function name, and an opening parenthesis: =MATCH( 3. Type the value to find, or click on the cell that contains the value -- cell A5 in this example 4. Type a comma, to separate the arguments 5. Select the range that contains the list -- a range named ItemList in this example 6. Type a comma, to separate the arguments 7. Type the number for the Match type you want to use -- 0 was used in this example, because an exact match is required. 8. Finish with a closing parenthesis. The completed formula is: =MATCH(A5,ItemList,0) 9. Press the Enter key to see the result.
A 1 Item B

2 Sweater 3 Jacket 4 Pants 5 Jacket =MATCH(A5,ItemList,0)

INDEX and MATCH -- Example One advantage of the INDEX/MATCH functions is that the lookup value can be in any column in the array, unlike the VLOOKUP function, in which the lookup value must be in the first column. In this example, the MATCH function will find the position of "Jacket" in column B, and the INDEX function will return the code from the same position in column A. 1. Set up the worksheet as shown at right 2. Enter the following formula in cell B6: =INDEX($A$2:$A$4,MATCH(A6,$B$2:$B$4,0)) 3. Press the Enter key to see the result. The MATCH function, MATCH(A6,$B$2:$B$4,0), returns 2, which is the position of "Jacket" in the list. Then, the INDEX function, INDEX($A$2:$A$4,2), returns "JK002", which is the second item in the range $A$2:$A$4. INDEX and MATCH -- Example 2 The MATCH function can be used to return values for both the row_num and column_num arguments in the INDEX function. 1. Set up the worksheet as shown at right 2. Enter the following formula in cell C7: =INDEX($B$2:$D$4,MATCH(B7,$A$2:$A$4,0),MATCH(A7,$B$1:$ D$1,0)) 3. Press the Enter key to see the result. The first MATCH function, MATCH(B7,$A$2:$A$4,0), returns 3, which is the position of "Pants" in the Items list. The second MATCH function, MATCH(A7,$B$1:$D$1,0), returns 2, which is the position of "Med" in the Size list. Then, the INDEX function, INDEX($B$2:$D$4,3,2), returns "30", which is the third item in the second column in the range $B$2:$D$4.
A 1 2 Sweater 3 4 5 6 Size 7 Med Item Pants Price ? Jacket Pants B Small 10 30 25 C 12 35 30 D 15 40 35 Med Large A 1 2 3 4 5 6 Code SW001 JK002 PN001 B Item Sweater Jacket Pants

Jacket

JK002

INDEX and MATCH -- Example 3


A B C D

To make the previous example even more flexible, you can use the INDEX 1 Small Med Large function within the MATCH function, to look for values in the first row or column 2 Sweater 10 12 15 of a named table. (from a newsgroup posting by Peo Sjoblom)
3 Jacket 30 35 30 Price ? 40 35 4 Pants 25 1. Set up the worksheet as shown at right 2. The green cells are a range named Table). (Instructions on naming a range) 5 3. Enter the following formula in cell C7: 6 Size Item =INDEX(Table,MATCH(B7,INDEX(Table,,1),0),MATCH(A7,INDEX(Ta 7 Med Pants ble,1,),0)) 4. Press the Enter key to see the result.

The first MATCH function, MATCH(B7,INDEX(Table,,1),0), looks for "Pants" in the first column of the Table range, and returns 3. The second MATCH function, MATCH(A7,INDEX(Table,1,),0), looks for "Med" in the first row of the Table range, and returns 2. Then, the INDEX function, INDEX(Table,3,2), returns "30", which is the third item in the second column in the range named Table. INDEX and MATCH -- Example 4
A B C D

Instead of matching information in column headings, you may need to match 1 Code Item Size Price information that's stored in the columns, as shown in the table at right. For example, 2 SW001 Sweater Small 10 instead of columns headings of Small, Med, and Large, you need to find the price 3 JK001 Jacket Small 30 in column D, when Jacket is in column B, and Med is in column C.
4 PN001 6 JK001 7 PN001 8 9 Item Size Med Price ? Pants Small Med Med

25

1. Set up the worksheet as shown at right 2. Enter the following formula in cell C10: =INDEX($D$2:$D$7,MATCH(1, (A10=$B$2:$B$7)*(B10=$C$2:$C$7),0)) 3. This is an array formula, so hold Ctrl + Shift, and press the Enter key to see the result. Curly brackets will be automatically added to the formula (don't type them yourself!), so the final result will look like this: {=INDEX($D$2:$D$7,MATCH(1,(A10=$B$2:$B$7)*(B10=$C$2:$C$7),0))} Note: You can adjust the ranges to match the data on your worksheet, but you can't refer to an entire column.

5 SW001

Sweater Med Jacket Pants

12

35

30

10 Jacket

Troubleshoot the MATCH formula Your MATCH formula may return an #N/A, even though the value you're looking for appears to be in the lookup array. Text vs. Number A common cause for this error is that one of the values is a number, and the other is text. For example, the lookup array may contain '123 (text), and the value to look up is 123 (a number). Or, if you have downloaded data from a database, it may contain text codes with leading zeros, e.g. 00123, and your Excel file may contain numbers formatted with leading zeros. If possible, convert the text to numbers, using one of the methods shown here: Convert Text to Numbers If you can't convert the data, you can convert the lookup value within the MATCH formula: Lookup values are Text, and the table contains Numbers If the lookup array contains numbers, and the value to look up is text, use a formula similar to the following: =MATCH(--A5,ItemList,0) The double unary (--) converts text to a number, and will work correctly even if the lookup values are numbers. Lookup values are Numbers, and the table contains Text If the lookup array contains text, and the value to look up is numeric, use a formula similar to the following: =MATCH(A5 & ""),ItemList,0) OR =MATCH(TEXT(A5,"00000"),ItemList,0) The TEXT function converts a number to text, and will work correctly even if the lookup values are text. In the first example, the & operator creates a text string from an unformatted number. In the second example, a number formatted with leading zeros (e.g. 00123) would match a text "number" with leading zeros. Spaces in one value, and not the other Another potential cause for no matching value being found is a difference in spaces. One of the values may contain leading spaces (or trailing, or embedded spaces), and the other doesn't. To test the values, you can use the LEN function, to check the length of each value. For example: =LEN(A5) will return the number of characters in cell A5. It should be equal to the number of characters in the matching cell in the lookup table. If possible, remove the unnecessary spaces, and the MATCH formula should work correctly. If you can't remove the spaces, use the TRIM function in the MATCH, to remove leading, trailing or duplicate spaces. For example:

=MATCH(TRIM(A5),ItemList,0) HTML characters in one value, and not the other If you copied data from a web page, it may contain non-breaking space (&nbsp) characters. David McRitchie has written a macro to remove them, along with other spaces characters -http://www.mvps.org/dmcritchie/excel/join.htm#trimall

Excel -- Worksheet Functions -- INDIRECT


Thanks to Dave Peterson, for his contributions to this page. INDIRECT Function Arguments Lock a Cell Reference Create a Reference from a Cell Value Create a Reference from a Cell Value and Text Create a Reference to a Different Sheet Create a Reference to a Different Workbook Refer to a Named Range Dependent Data Validation Lists The INDIRECT function returns a reference to a range. You can use this function to create a reference that won't change if row or columns are inserted in the worksheet. Or, use it to create a reference from letters and numbers in other cells. Download zipped sample workbook

INDIRECT Function Arguments The INDIRECT function has two arguments: 1. ref_text: A cell reference or text string (or both), that create the range reference. The referenced range can be a cell, a range of cells, or a named range. 2. a1: TRUE or FALSE. Does the reference use A1 reference style? If this argument is TRUE, or omitted, the ref_text is A1 style. If the argument is FALSE, the ref_text is R1C1 style. Note: If the INDIRECT formula refers to a different workbook, that workbook must be open, or the formula will return a #REF! error. Lock a Cell Reference If you create a simple link to a cell, e.g. =A4, then insert a row above row 4, your formula will automatically change to =A5. To prevent this change, you can use the INDIRECT function. To demonstrate the difference, you'll create two formulas -- one that uses a simple link, and one that uses a text string in an INDIRECT formula. 1. In cell A4, type a number (10 in this example). 2. In cell B2, type the following formula: =INDIRECT("A4") 3. Press the Enter key, and the formula will return the number in cell A4. 4. In cell C2, type the following formula: =A4 5. Press the Enter key, and the formula will return the number in cell A4. 6. To insert a row, right-click on the Row 4 button, and from the pop-up menu, choose Insert. 7. As shown at right, cell B2, which contains the INDIRECT formula, now returns 0, because cell A4 is empty. The text string, "A4", in the INDIRECT formula did not change when the row was inserted. 8. Cell C2, which contains the link, still returns 10, because its formula has changed to =A5. Create a Reference from a Cell Value To create the ref_text argument, you can also refer to a cell, and use its contents. This makes the formula more flexible, as its results will change, if the cell contents

change. In this example, you'll create INDIRECT formulas, to compare the A1 and R1C1 reference styles. 1. In cells A1:A5, type a set of numbers, as shown at right. 2. In cell C2, type: A4 3. In cell C2, type: R4C1 4. In cell D2, type the formula: =INDIRECT(C2) 5. Press the Enter key, and the formula returns the number in cell A4 6. In cell D3, type the formula: =INDIRECT(C3,FALSE) 7. The FALSE in the second argument indicates that the R1C1 reference style will be used. 8. Press the Enter key, and the formula returns the number in cell A4 Create a Reference from a Cell Value and Text To create the ref_text argument, you can combine text strings and cell references withing the INDIRECT formula. In this example, you'll create an INDIRECT formula, using a number entered in a cell, and a text string with the column letter. 1. In cells A1:A5, type a set of numbers, as shown at right. 2. In cell C2, type the number 4. 3. In cell D2, type the formula: =INDIRECT("A"&C2) 4. Press the Enter key, and the formula returns the number in cell A4 5. Change the number in cell C2, and the result in D2 will change. Note: If cell C2 is empty, the formula will return an error. To prevent this, you can add an IF function: =IF(C2="",0,INDIRECT("A"&C2)) Create a Reference To a Different Sheet An INDIRECT formula can also refer to cells on other worksheets. In this example, you'll create an INDIRECT formula, using references to a sheet name and cell name.

1. On a worksheet named Data Sheet, enter numbers in cells A1:A10 2. On a different sheet, in cell A2, enter the sheet name: Data Sheet 3. In cell B2, type a cell name from the range of numbers, e.g.: A2 4. In cell C2, type the following formula: =INDIRECT("'" & A2 & "'!" & B2) 5. The first part of the string is a single quote within a set of double quotes: " ' " (spaces were added for clarity) 6. After the reference to A2, which contains the sheet name, is a single quote and apostrophe, within a set of double quotes: " ' ! " (spaces were added for clarity) 7. The string ends with a reference to cell B2, which contains the cell address. 8. Single quotes are included in the string to prevent errors if the sheet name contains space characters. 9. Press the Enter key, and the formula returns the number in cell A2 on the Data Sheet worksheet. 10. Change the number in cell C2, and the result in D2 will change. Note: If either cell A2 or B2 is empty, the formula will return an error. To prevent this, you can add an IF function: =IF(OR(A2="",B2=""),"",INDIRECT("'" & A2 & "'!" & B2)) Create a Reference To a Different Workbook An INDIRECT formula can refer to cells in other workbooks, but will return a #REF! error if that workbook is closed. In this example, you'll create an INDIRECT formula, using references to a file name, sheet name and cell name.

1. In an open file named TestFile.xls, on a worksheet named Test Data, enter numbers in cells A1:A10 2. On a sheet in a different workbook, in cell A2, enter the file name: Test File.xls 3. In cell A3, enter the sheet name: Test Data 4. In cell A4, type a cell name from the range of numbers, e.g.: A7 5. To see the syntax that you'll need to use in your formula, select cell A7, and type an equal sign: = 6. Switch to Test File.xls, and click on cell A7 7. In the formula bar, you'll see the reference that was created: ='[Test File.xls]Test Data'!$A$7 8. You'll create an INDIRECT formula that uses the same syntax, adding the single quote marks, square brackets and apostrophe. 9. In cell A6, type the following formula: =INDIRECT("'[" & A2 & "]" & A3 & "'!" & A4) 10. The first part of the string is a single quote and square bracket, within a set of double quotes: " ' [ " (spaces were added for clarity) 11. After the reference to A2, which contains the file name, is a square bracket, within a set of double quotes: " ] " (spaces were added for clarity) 12. After the reference to A3, which contains the sheet name, is a single quote and apostrophe, within a set of double quotes: " ' ! " (spaces were added for clarity) 13. The string ends with a reference to cell A4, which contains the cell address. 14. Single quotes are included in the string to prevent errors if the sheet name contains space characters. 15. Press the Enter key, and the formula returns the number in cell A7 on the Test Data worksheet, in the Test File.xls workbook. 16. Change the values in cells A2:A5, and the result in A6 will change. 17. You can delete the sample link in cell A5. Note1: If A2, A3 or A4 is empty, the formula will return an error. To prevent this, you can add an IF function: =IF(OR(A2="",A3="",A4=""),"",INDIRECT("'[" & A2 & "]" & A3 & "'!" & A4)) Note2: If the Test File.xls workbook is closed, the above formula will return a #REF error. I haven't used the following files, but they may help you if you need to pull

data from a closed workbook:

Harlan Grove wrote a UDF called PULL that will retrieve the value from a closed workbook. You can find the function at Harlan's FTP site: ftp://members.aol.com/hrlngrv/ Look for pull.zip Laurent Longre has an addin (morefunc.xll) at: http://xcell05.free.fr/ It includes =indirect.ext() that may help you. Refer to a Named Range

In addition to cell references, you can refer to named ranges in an INDIRECT formula. In this example, INDIRECT is used to sum the selected named range. 1. In cells A1:B5, type headings and numbers, as shown at right. 2. Name cells A2:A5 as East, and cells B2:B5 as West. There are naming instructions here: Names -- Naming
Ranges

3. In cell D2, type the name of one of the ranges, e.g. East 4. In cell E2, type the formula: =SUM(INDIRECT(D2)) 5. Press the Enter key, and the formula returns the sum of numbers in the East range. 6. Change cell D2 to West, and the formula returns the sum of numbers in the West range. Dependent Data Validation Lists The INDIRECT function can be used with Data Validation, to create dependent dropdown lists. For example, select the Fruit category in column A, and the data validation list in column B shows a list of Fruit options. There are instructions for this technique here: Data Validation - Dependent Lists

Excel -- Worksheet Functions -- Sum Cells


Sum a range of cells -- SUM Sum a range of cells -- OFFSET Grand Total a range of cells Sum cells that match criteria -- SUMIF - Match criterion exactly - Match criterion in a string - Match criterion using operator Sum cells that match multiple criteria -- SUMPRODUCT

AutoSum Download zipped sample workbook

Sum the Top 5 Numbers in a List Sum the Numbers in a Filtered List

Sum a range of cells -- SUM The SUM function will add the numbers in a range of cells. Its syntax is: =SUM(number1, number2,...number30). The arguments (e.g. number1) can be cell references, or typed into the formula. The following example uses one argument -- a reference to cells A1:A4. 1. Select the blank cell in the row below the cells that you want to sum, cell A5 in this example. 2. Click the AutoSum button on the Standard toolbar A SUM formula will appear in the active cell 3. Press the Enter key to complete the entry.
o

Note: Instead of using the AutoSum button, you could type the formula into the cell. Sum a range of cells -- OFFSET If you insert a row directly above the SUM formula in the previous example, the new row may not be included in the SUM. It may continue to sum cells A1:A4, and ignore A5. To ensure that new rows are included in the total, you can use the OFFSET function. 1. Select cell A5. 2. Enter the following formula: =SUM(A1:OFFSET(A5,-1,0)) 3. Press the Enter key to complete the entry. 4. Insert a row above row 5 5. Type a number in cell A5, and it will be included in the total in cell A6

Grand Total a range of cells You can calculate row totals, column totals, and a grand total for a range of cell, all in one step. 1. Select the range of cells, and the blank row below the range, and the blank cells in the column to the right (cells A1:D5 in the example at right) 2. Click the AutoSum button on the Standard toolbar
o

A SUM formula will be entered for each Total

Sum cells that match criteria -- SUMIF Match criterion exactly You can calculate a total for rows that meet a specific criterion. In this example only the rows with Pen orders will be included in the total. 1. 2. 3. 4. 5. 6. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked Type a comma, to separate the arguments Type the criterion. In this example, you're checking for text, so type the word in double quotes: "Pen" Note: upper and lower case are treated equally Type a comma, to separate the arguments Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed The completed formula is: =SUMIF(A2:A10,"Active",B2:B10)

7. 8. 9.

10. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10, B12, B2:B10) if cell B12 contained the text pen.

Match criterion in a string You can add cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be summed, because they contain the string "pen". 1. Select the cell in which you want to see the total (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: SUMIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters: "*Pen*" Note: upper and lower case are treated equally 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed 9. Type a closing bracket. The completed formula is: =SUMIF(A2:A10,"*Pen*",B2:B10) 10. Press the Enter key to complete the entry 11. The result will be 53, the total of rows that contain the string, "Pen" Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10,"*" & B12 & "*",B2:B10) if cell B12 contained the text pen.

Criterion and operator You can use an operator with a criterion. In this example only the rows where the number of sales reps is greater than or equal to ten will be included in the total. 1. 2. 3. 4. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells B2:B10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for rows where the number of visits is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes. 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum 9. Type a closing bracket. The completed formula is: =SUMIF(B2:B10,">=10",C2:C10) 10. Press the Enter key to complete the entry 11. The result will be 183, the total of rows with ten or more sales reps. Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(B2:B10,">=" & B12,C2:C10) if cell B12 contained the number 10. Sum cells that match multiple criteria -- SUMPRODUCT Match multiple criteria You can calculate a total for rows that meet two or more criteria. In this example only the rows where the status is "Active" and the number of visits is greater than or equal to ten will be included in the total.

1. 2. 3. 4.

Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMPRODUCT(--( Select the cells that contain the values to check for the first criterion. In this example, cells A2:A6 will be checked 5. Type the first criterion: ="Active" 6. Type ),--( 7. Select the cells that contain the values to check for the second criterion. In this example, cells B2:B6 will be checked 8. Type the second criterion: >=10 9. Type ),--( 10. Select the cells that contain the values to sum. In this example, cells C2:C6 will be summed 11. Finish with closing brackets: )) 12. The completed formula is: =SUMPRODUCT(--(A2:A6="Active"), --(B2:B6>=10),-(C2:C6)) 13. Press the Enter key to complete the entry

Sum the Top 5 Numbers in a List Use the SUM and LARGE functions together, to add the largest numbers in the list.

Version 1 -- Few Top Numbers


If a few numbers are to be summed, e.g. top 3, you can type the numbers into the formula. For example: =SUM(LARGE(A1:A7,{1,2,3})) The result is 70+60+50 = 180 Note: The second 50 is not included in the result, even though it is tied for 3rd place.

Version 2 -- Many Top Numbers


If many top numbers are to be summed you can include the INDIRECT function in the formula. In the INDIRECT function, use row numbers that represent the numbers you want to include. In this example, rows 1:10 are used, so the top 10 numbers in the referenced range will be summed. 1. Type the formula: =SUM(LARGE(A1:A50,ROW(INDIRECT("1:10")))) 2. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter

Version 3 -- Variable Top Numbers


If a variable number of top numbers are to be summed you can include the INDIRECT function in the formula, as shown above, and refer to a cell that holds the variable.. 1. In cell C1, type the number of top cells, e.g. 10 2. Type the formula: =SUM(LARGE(A1:A7,ROW(INDIRECT("1:"&C1)))) 3. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter Sum the Numbers in a Filtered List After you filter the rows in a list, you can use the SUBTOTAL function to sum the numbers in the visible rows. 1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics 2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders. 3. Select the cell immediately below the column you want to sum. 4. Click the AutoSum button on the Excel's Standard toolbar. o If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button. 5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column o The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. There is a 9 in this example, which tells Excel to SUM the numbers.

Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list. 6. Press the Enter key to complete the formula entry.
o

Note: In Excel 2003, you can use the formula: =SUBTOTAL(109,B2:B9) to subtotal visible cells in a range where rows have been manually hidden, or filtered. Download zipped sample workbook

Excel -- Pivot Tables -- Add-In


Add-In Features The Add-In features are described here. Download PivotPower.xla add-in Beta 2.7 Download the PivotPower.zip file To install the Add-in: 1. Download the PivotPower.zip file 2. Unzip the file 3. Save the PivotPower.xla file in your Microsoft\Addins folder. For example, in Windows XP, this might be: C:\Documents and Settings\Contextures\Application Data\Microsoft\AddIns 4. Open Excel 5. Choose Tools | Add-Ins 6. Click the Browse button 7. Find and select the PivotPower.xla add-in

8. Click OK, click OK 9. A PIVOT menu will appear on your Excel menu bar. Use it to perform tasks with your pivot tables, such as clearing old items, and removing all subtotals. No Help is available for the Beta version. If you have comments or suggestions, please contact ddalgleish@contextures.com

Excel -- Pivot Tables -- Pivot Play PLUS Add-In


Thanks to Ron Coderre, who created this add-in. If your Pivot or Query Table is based on an External Data Query, Pivot Play PLUS was built to help you easily edit the Connection String to the data source and the Query itself. It also contains a handful of other features to help you manage your pivot and query tables in Excel 2002 and Excel 2003. Pivot Play Add-In Features General Usage Processing Options Data Source Settings Global Settings About the Developer Download Pivot Play PLUS To download the add-in file click this link: PivotPlayPLUS.zip
(for Excel 2002 and Excel 2003 only)

Install Pivot Play PLUS Installation Instructions

General Usage

The Main Page (see illustration below) opens with a list of all Pivot and Query Tables that are on the active worksheet (along with key information about each of those tables). If a cell within one of those tables is selected when Pivot Play PLUS is engaged, that table will be the default item selected on the list. Whenever a listed table is selected, additional information about that pivot table displays in the lower section of the Main Page. If the table data is based on an External Data Source, the Connection and Query information will be displayed and the Edit Settings button will be visible. Otherwise, a message that the source is not based on external data displays. To change the Connection Info or Query Info, click the Edit Conn/Qry Settings button. to open the Edit Settings For page.

Processing Options When a table from the list is selected, one or more option buttons, depending on whether the selected item is a Pivot Table or a Query Table. Each button's text indicates its functionality:

Refresh Data: Retrieves the latest data into the Pivot or Query Table. Rename: allows you to give the selected Table a more descriptive name. Clear Invalid Field Names: removes dropdown list items that have no representation in the source data. (Pivot Tables ONLY).

Data Source Settings Clicking on the Edit Settings button opens a window displaying the Connection and Query details. Use this page to:

Edit the Connection Settings to the data source. The upper section of the page displays the current Connection settings. This is where you change the location of the data source and any other Connection String settings. Edit the Query Settings that extract data into the pivot cache. The lower section of the page displays the current query settings. Edit the SQL in this section.

An additional feature in this section is the Read Query From a Cell button, which allows you to select a single cell in the workbook that contains the SQL to be used by the Pivot or Query Table. That reference can be a cell reference or a named range. In either case, the contents of the cell are read and written into the Table settings; the Table itself is NOT linked to the cell Finally, the Connection Settings and Query Settings sections have buttons to restore their respective settings to the original values. NOTE: If the edited settings prove to be invalid when saving, you may continue editing the them or click the Restore button see the original values.

Global Settings The Turn GetPivotData On/Off button toggles Excel's automatic GetPivotData function generation on/off. The Reset Pivot Play PLUS Startup Settings button returns the Pivot Play StartUp options to their defaults. This includes displaying the Pivot Play splash screen upon opening. About the Developer When he's not sailing, Ron Coderre is a Business Systems Analyst and Application Developer at Teradyne, Inc. in Boston, where he works within the Finance organization to provide extensible, automated, process re-engineering solutions targeted at increasing the productivity of financial analysts and reducing analytical task duration. Inherent in his finished products are intuitive user interfaces, accurate data, the ability to easily adjust data scenarios, and publication-ready reports. Ron is also an Ron Coderre Essbase expert and provides technical training. To install the Add-in: 1. Download the PivotPlayPLUS.zip file 2. Unzip the file 3. Save the PivotPlayPLUS.xla file in your Microsoft\Addins folder. For example, in Windows XP, this might be: C:\Documents and Settings\Contextures\Application Data\Microsoft\AddIns (If you have previously installed the PivotPlay.xla add-in..Delete that file) 4. Open Excel 5. Choose Tools | Add-Ins 6. Click the Browse button 7. Find and select the PivotPlayPLUS.xla add-in 8. Click OK, click OK 9. A Pivot Play PLUS command will appear on the Data menu.

Excel -- Pivot Tables -- Custom Calculations


1. 2. 3. 4. 5. 6. 7. 8. % of Column % of Row % of Total Difference from % Difference from % Of Running Total in Remove a Custom Calculation

Amazon.com Download the zipped sample file In a Pivot Table, you can summarize the data by using the values in other cells in the data area.

For example, you can show each Region's total as a percentage of the national total. Or, calculate the difference between the sales totals for the current year, and the sales totals for the previous year. The examples shown here are based on this zipped sample file .

% of Column In this example, the pivot table has Region in the Row area, and Total in the Data area. A custom calculation will be added, to show the percentage for each region's sales, compared to the national total. 1. From the Pivot Table field list, drag another copy of the Total field to the Data area. 2. If the data fields are arranged vertically, you can change them to a horizontal layout, by following the instructions here. 3. Right-click the heading cell for the new column, and select Field Settings... 4. In the Field Settings dialog box, type a name for the field, e.g. %Sales 5. Click the Options button, to expand the dialog box 6. From the Show data as dropdown list, select % of column 7. Click the OK button % of Row In this example, the pivot table has Item in the Row area, Region in the Column area, and Total in the Data area. The total will be changed to a custom calculation, to show the percentage for each region's sales of an item, compared to the item total. 1. Right-click one of the cells in the Data area, and select Field Settings... 2. In the Field Settings dialog box, type a name for the field, e.g. %Sales 3. Click the Options button, to expand the dialog box 4. From the Show data as dropdown list, select % of row 5. Click the OK button % of Total In this example, the pivot table has Item in the Row area, Region in the Column area, and Total in the Data area. The total will be changed to a custom calculation, to show the percentage for each region's sales of an item, compared to the Sales Grand Total for all Items. 1. Right-click one of the cells in the Data area, and select Field Settings... 2. In the Field Settings dialog box, type a name for the field, e.g. %Sales 3. Click the Options button, to expand the dialog box

4. From the Show data as dropdown list, select % of Total 5. Click the OK button

Difference from In this example, the pivot table has Region in the Row area, and Total in the Data area. Date is in the Column area, grouped by Year. There are instructions here for grouping data. The total will be changed to a custom calculation, to compare the current year's sales for each region, to previous year's sales, in dollars. 1. Right-click one of the cells in the Data area, and select Field Settings... 2. In the Field Settings dialog box, type a name for the field, e.g. Change 3. Click the Options button, to expand the dialog box 4. From the Show data as dropdown list, select Difference From 5. From the Base field list, choose Years 6. From the Base item list, choose (previous) 7. Click the OK button

% Difference from In this example, the pivot table has Item in the Row area, and Total in the Data area. Date is in the Column area, grouped by Year. There are instructions here for grouping data. The total will be changed to a custom calculation, to compare the current year's sales for each Item, to previous year's sales, as a percentage. 1. Right-click one of the cells in the Data area, and select Field Settings... 2. In the Field Settings dialog box, type a name for the field, e.g. %Change 3. Click the Options button, to expand the dialog box 4. From the Show data as dropdown list, select % Difference From 5. From the Base field list, choose Years 6. From the Base item list, choose (previous) 7. Click the OK button % Of In this example, the pivot table has Item in the Row area, Region in the Column area, and Total in the Data area. The total will be changed to a custom calculation, to compare each Region's sales to Ontario's sales, as a percentage. 1. Right-click one of the cells in the Data area, and select Field Settings... 2. In the Field Settings dialog box, type a name for the field, e.g. %Ontario 3. Click the Options button, to expand the dialog box 4. From the Show data as dropdown list, select % Of 5. From the Base field list, choose Region 6. From the Base item list, choose Ontario 7. Click the OK button Running Total in In this example, the pivot table has Region in the Column area, and Total in the Data area. Date is in the Row area, grouped by Year and Quarter. There are instructions here for grouping data. The total will be changed to a custom calculation, to calculate a running total of sales for each

Region, over each Year. 1. Right-click one of the cells in the Data area, and select Field Settings... 2. In the Field Settings dialog box, type a name for the field, e.g. Sales 3. Click the Options button, to expand the dialog box 4. From the Show data as dropdown list, select Running Total in 5. From the Base field list, choose Date 6. Click the OK button

Remove a Custom Calculation To remove a custom calculation from a pivot table: 1. Click the dropdown arrow on the Data field button 2. Remove the check mark from the custom calculation. Note: If you remove an item from the data area, it's removed from the pivot table. To replace it, you can drag it back from the pivot table field list. 1. Pivot Tables -- Dynamic Data Source 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData 7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Excel -- Pivot Tables -- Data Field Layout


1. Arrange Multiple Data Fields

2. Rename Data Fields Download the zipped sample file

Table of Contents Arrange Multiple Data Fields If you place two fields in the Data area of a Pivot Table, they appear vertically arranged. To make the data easier to read, you can rearrange the table.

1. Point to the grey button for the Data field 2. Hold the left mouse button, and drag the Data button onto the cell which contains the word 'Total' 3. Release the mouse button The Data fields will now be arranged horizontally. View video demonstration

Rename Data Fields When you add fields to the Data area, they are renamed, e.g. 'Units' becomes 'Sum of Units'. There are several ways to change the names, but the following is probably the easiest. 1. Select the heading cell in the Pivot Table. 2. Type a new heading. 3. Press the Enter key. Note: The typed name can't be the same as the original field name, i.e., you can't change 'Sum of Units' to 'Units'. However, you can type the original field name, and add a space character at the end, e.g. 'Units ' 1. Pivot Tables -- Dynamic Data Source 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData

7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Excel -- Pivot Tables -- Dynamic Data Source


1. Pivot Tables -- Introduction Getting Started Use a Dynamic Data Source

Getting Started Many books and web sites have information on creating Pivot Tables in Excel 2003, and earlier versions. For a brief introduction, and list of Pivot Table links, visit Jon Peltier's site. You can download the zipped sample file used for this example. Use a Dynamic Data Source You can use a dynamic formula to define the source range for a Pivot Table. As new items are added to the table, the named range will automatically expand. 1. Name the Range 1. Choose Insert>Name>Define 2. Type a name for the range, e.g. Database 3. In the Refers To box, enter an Offset formula that defines the range size, based on the number of items in a column that doesn't contain any blank cells. , e.g.: =OFFSET(Data!$A$1,0,0,COUNTA(Data! $A:$A),7) In this example, the list is on a sheet named 'Data', starting in cell A1. The arguments used in this Offset function are: 1. Reference cell: Data!$A$1 2. Rows to offset: 0 3. Columns to offset: 0 4. Number of Rows: COUNTA(Data!$A: $A) 5. Number of Columns: 7 Note: for a dynamic number of columns, replace the 7 with: COUNTA(Data! $1:$1)

Table of Contents

4. Click OK 2. Base the Pivot Table on the Named Range 1. Select a cell in the database 2. Choose Data>PivotTable and PivotChart Report 3. Select 'Microsoft Excel List or Database', click Next. 1. Pivot Tables -- Introduction 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData 7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Excel -- Pivot Tables -- Field Settings


1. 2. 3. 4. 5. Manually Hide or Show Subtotals Programmatically Hide Subtotals Show Items with No Data Show Top Items Only Sort All Fields in Ascending Order

Download the zipped sample file


Amazon.com

Manually Hide or Show Subtotals To manually hide subtotals for a field: 1. Double-click the field button, to open the PivotTable field dialog box. 2. For Subtotals, select 'None' 3. Click OK To manually show subtotals for a field: 1. Double-click the field button, to open the PivotTable field dialog box. 2. For Subtotals, select 'Custom' 3. Select one of the functions from the list, e.g. 'Average' 4. Click OK Programmatically Hide Subtotals You can use a macro to hide subtotals in a PivotTable. This example uses the PivotField property, to hide all the subtotals. To hide only the Row field subtotals, use the RowFields property. To hide only the Column field subtotals, use the ColumnFields property.
Sub NoSubtotals() 'turns off subtotals in pivot table '.PivotFields could be changed to '.RowFields or .ColumnFields Dim pt As PivotTable Dim pf As PivotField For Each pt In ActiveSheet.PivotTables For Each pf In pt.PivotFields 'Set index 1 (Automatic) to True, 'so all other values are set to False pf.Subtotals(1) = True pf.Subtotals(1) = False Next pf Next pt End Sub

Show Items with No Data By default, the Pivot Table shows only the items for which there is data. In the example shown at right, not all colours were sold each day. You may wish to see all the items each day, even those with no data. 1. Double-click the field button, to open the PivotTable field dialog box. 2. Check the 'Show items with no data' check box. 3. Click OK

Show Top Items Only Instead of showing all the items in a field, you can restrict the Pivot Table to show only the top (or bottom) items. 1. Double-click the field button, to open the PivotTable field dialog box. 2. Click the Advanced button 3. Under 'Top 10 AutoShow', select On. 4. For 'Show', select Top or Bottom 5. Click the Scroll buttons, or type, to enter the number of items to show. 6. Click OK, click OK Sort All Fields in Ascending Order After adding new records to your data, new items may appear at the end of the existing data, instead of being listed alphabetically. The following code will sort all fields in all pivot tables.
Sub SortAllFields() On Error Resume Next Application.ScreenUpdating = False Dim pt As PivotTable Dim ws As Worksheet Dim pf As PivotField For Each ws In ActiveWorkbook.Worksheets For Each pt In ws.PivotTables pt.ManualUpdate = True For Each pf In pt.PivotFields pf.AutoSort xlAscending, pf.Name Next pf pt.ManualUpdate = False Next pt Next ws Application.ScreenUpdating = True End Sub

1. Pivot Tables -- Dynamic Data Source 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData 7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Answers to Frequently Asked Questions about Microsoft Excel

Pivot Tables and Pivot Charts


1. Pivot Tables 1. How do I display text in the data area of a pivot table? 2. Is it possible to use multiple sources of data to produce a pivot
table?

3. I added new rows/columns to the pivot table source data, and


they don't appear when I refresh the pivot table

4. How do I get row field headings to repeat in a pivot table? 5. I am trying to group dates by month and get an error that says Table of Contents
'Cannot Group that selection'

6. When I refresh the pivot table, how can I preserve my formatting? 7. How can I make two data fields appear side-by-side, instead of in 8. 9. 10. 11.
separate rows? How do I clear old values from the pivot table dropdowns? I've inherited workbooks with pivot tables based on an Access query. How can I find what the datasource is? When I link to a pivot table cell, a GetPivotData formula is created. How can I turn this off? Can I change the default summary function for data from COUNT to SUM?

Table of Contents 2. Pivot Charts 1. When I refresh the pivot chart, my formatting is lost. How do I
preserve it?

2. How do I remove the 'Drop Page Fields Here' labels on the Pivot 3. 4.
Chart? How can I add a horizontal line to a Pivot Chart? How can I change my Pivot Chart without changing the Pivot Table?

1. Pivot Tables

How do I display text in the data area of a pivot table?

You can't display text data in the data area of a pivot table. You could display the text fields in the Row and Column areas, and show a count of the records in the data area.
Is it possible to use multiple sources of data to produce a pivot table?

You can create a pivot table from data on separate sheets (multiple consolidation ranges), but the results may not be exactly what you want. There's more information here: http://www.contextures.com/xlPivot08.html
I added new rows/columns to the pivot table source data, and they don't appear when I refresh the pivot table.

If the new fields are outside the pivot table's data range, they won't show up in the field list. To adjust the range: 1. 2. 3. 4. Right-click a cell in the pivot table Choose PivotTable Wizard Click the Back button, and select the new range Click Finish.

Or use a dynamic range as the pivot table source, and it will adjust automatically. There are instructions here: http://www.contextures.com/xlPivot01.html
How do I get row field headings to repeat in a pivot table?

The row headings show once in a Pivot Table, and there's no setting you can change, to force them to repeat. To create a table with a heading on each row, you could copy the pivot table, paste it as values in another location, and fill in the blanks, using the technique shown here: http://www.contextures.com/xlDataEntry02.html .
I am trying to group dates by month and get an error that says 'Cannot Group that selection'.

If the field contains blank cells, or cells with text, you'll get that error. There are some suggestions for fixing the problem here: http://www.contextures.com/xlPivot07.html#Problems
When I refresh the pivot table, how can I preserve my formatting?

1. Right-click a cell in the pivot table, and choose Table Options 2. Ensure that Preserve Formatting is turned on, and AutoFormat is turned off, then click OK To format cells, enable selection should be turned on. To enable selection: 1. From the Pivot toolbar, choose PivotTable>Select 2. If it's not already activated, click on Enable Selection To format a section of a pivot table, e.g. subtotals: 1. Move the pointer to the left of a subtotal heading in the pivot table. 2. When the black arrow appears (like the one that appears when the pointer is over a row button), click to select the subtotal rows in the pivot table. 3. Format the selected subtotal
How can I make two data fields appear side-by-side, instead of in separate rows?

2. Pivot Charts
When I refresh the pivot chart, my formatting is lost. How do I preserve it?

Loss of formatting is a known problem with pivot charts. There's information in the following MSKB article, which suggests recording a macro as you apply the formatting: Changing a PivotChart removes series formatting in Excel http://support.microsoft.com/?id=215904 You could record a macro as you format the chart, and change the recorded series number to names. Then run that macro after you change the pivot table.
How do I remove the 'Drop Page Fields Here' labels on the Pivot Chart?

With the pivot chart selected, on the pivot toolbar, choose PivotChart>Hide PivotChart Field buttons.
How can I add a horizontal line to a Pivot Chart?

You could create a normal chart, based on the pivot table, and include the line in that. On Jon Peltier's site, there are instructions for creating a normal chart from pivot data: http://www.peltiertech.com/Excel/Pivots/pivotcharts.htm
How can I change my Pivot Chart without changing the Pivot Table?

Create another pivot table, based on the first one. Then, create the pivot chart from the second pivot table. You can hide the sheet that contains the second pivot table. When you change the pivot chart, only the hidden pivot table will be affected.

Excel -- Pivot Tables -- GetPivotData


1. Generate GetPivotData 2. GetPivotData Formula 3. Using Cell References in GetPivotData Download the zipped sample file

Amazon.com

Generate GetPivotData In Excel 2002, and later versions, when you type an equal sign, then click on a cell in a pivot table, you may see a GETPIVOTDATA formula, instead of a cell reference. If you prefer to use a cell reference, you can:

type the reference, e.g. =$B$5

or

add the Generate GetPivotData button to a toolbar, to turn this feature off.

To add a Generate GetPivotData button: 1. On the PivotTable toolbar, click the Toolbar Options button 2. Click the Add or Remove Buttons command 3. Click PivotTable, to open the submenu 4. Near the end of the commands list, click on Generate GetPivotData to add a check mark. 5. Click on the worksheet, to close the menu. On the PivotTable toolbar, click the Generate GetPivotData button to toggle this feature on and off. Watch the Video View the steps to customize the toolbar, in a short video clip. GetPivotData Formula To extract data from a PivotTable, you can use the GetPivotData function. The function arguments depend on the version of Excel that you're using, so check Excel's on-line help for examples. The example at the right is for Excel 2002, and returns the number of Units sold in Ontario. In Excel 2002, if you have the Generate GetPivotData feature turned on, this formula will be created automatically, when you reference a cell in the Pivot Table.

In Excel 2000 or Excel 97, you have to create the GetPivotData formula manually, by typing an equal sign, the function name, and the required arguments, just as you would for any other function. This example shows the function arguments required for Excel 2000 or Excel 97, to return the number of Units sold in Ontario.

This example shows the function arguments required for Excel 2000 or Excel 97, to return the total number of Units sold.

Using Cell References in GetPivotData Instead of typing item or field names in the GetPivotData arguments, you can refer to worksheet cells. In this example for Excel 2002, cell A10 contains one of the arguments, and the formula refers to that cell. In this example for Excel 2000, cell A10 contains one of the arguments, and the formula refers to that cell. A space is included at the end of "Units ". If this is omitted, the formula will return an #N/A error. In the next example, both arguments come from cell references, and a space character is concatenated in the middle, using the & operator. 1. Pivot Tables -- Dynamic Data Source 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData 7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Excel -- Pivot Tables -- Grand Totals


1. Show Grand Total at Top

Amazon.com

Show Grand Total at the Top of a Pivot Table There's no setting that allows you to display the grand total at the top of a pivot table. However, with this technique you can use another field that acts as the grand total, and display it at the top. Note: The instructions and sample file are for Excel 2003 and earlier. Download the zipped sample file

Create the fake "Grand Total" field


1. In the source data, add a column with the heading GT, or use a space character as the column heading 2. In every row of the source data, for the GT field, enter: Grand Total 3. Add this field to the pivot table, as the first field in the Row area

Change the Field Settings


1. In the pivot table, right-click on the GT field button, and click Field Settings 2. Click the Layout button 3. Click Show Items in Outline Form 4. Add a check mark to Display Subtotals at Top of Group 5. Click OK, twice.

Hide the original Grand Total


1. Right-click on a cell in the Pivot Table 2. Click Table Options 3. Remove the check mark for Grand Totals for Columns 4. Click OK

1. Pivot Tables -- Dynamic Data Source 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData 7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Excel -- Pivot Tables -- Grouping Data


1. 2. 3. 4. Grouping Dates Grouping Dates by Week Problems when Grouping Data Count Unique Items

Download the zipped sample file

Amazon.com

In a Pivot Table, you can group the items in a Row or Column field. For example, items in a date field can be grouped by month, and items in a number field can be grouped by tens.

Grouping Dates To group the items in a Date field 1. Right-click the Date field button. 2. Choose Group and Show Detail | Group 3. In the Grouping dialog box, select one or more options from the 'By' list. 4. To limit the dates that are grouped, you can set a Start and End date, by typing the dates in the 'Starting at' and 'Ending at' boxes 5. Click OK

Grouping Dates by Week To group the items in a Date field by week 1. Right-click the Date field button. 2. Choose Group and Show Detail | Group 3. In the Grouping dialog box, select Days from the 'By' list. 4. For 'Number of days', select 7 5. The week range is determined by the date in the 'Starting at' box, so adjust this if necessary. In the example at right, December 29, 2003 (a Monday), was entered as the starting date. 6. Click OK Problems when Grouping Data If you try to group a date or field, you may see an error message that says, "Cannot group that selection." This problem usually occurs when the field contains records with a blank date/number field, or text in a date/number field. To fix the problem

For blank cells, fill in the date/number (use a dummy date/number if necessary). If there is text in the date/number field, remove it. If numbers are being recognized as text, use

one of the techniques shown here to change them. If you don't have blank cells or text in the date column, there may be a grouped field left over from the previous time that you grouped the data. 1. Check the field list, to see if there's a second copy of the date field, e.g. Date2. 2. If there is, add it to the row area, and ungroup it. 3. Then, you should be able to group the date field again. Count Unique Items In a pivot table, you may want to know how many unique customers placed an order for an item, instead of how many orders were placed. A pivot table won't calculate a unique count. However, you could add a column to the database, then add that field to the pivottable. For example, to count the unique occurences of a Customer/Item order, add a column to your database, with the heading 'CustItem' In the first data row, enter a formula that refers to the customer and item columns. For example: =IF(SUMPRODUCT(($A$2:$A2=A2)*($C$2:$C2=C2))>1,0,1) Copy the formula down to all rows in the database. Then, add the field to the data area of the pivot table. In this example, you can see that nine unique customers placed an order for binders, and there were 14 orders for binders. 1. Pivot Tables -- Dynamic Data Source 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData 7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Excel -- Pivot Tables -Multiple Consolidation Ranges


1. Create a pivot table from multiple consolidation ranges 2. Limitations of multiple consolidation ranges Download the sample file
Amazon.com

To create a Pivot Table, you can use data from different sheets in a workbook, or from different workbooks, if those tables have identical column structures. However, you won't get the same pivot table layout that you'd get from a single range.

Source data

Create a pivot table from multiple consolidation ranges 1. Choose Data | PivotTable and PivotChart Report 2. Select Multiple consolidation ranges, click Next 3. Select one of the page options, click Next 4. Select each range, and click Add 5. If you chose 'I will create the page fields', you can select each range, and assign field names, in step 2b 6. Click Next

1. Select a location for the PivotTable, click Finish 2. In the Column dropdown, hide any columns that contain meaningless data.

Limitations of Multiple Consolidation Ranges In this example, Item is the first column in the data source, and the pivot table row heading shows the item names. Remaining fields are shown in the column area.

You can change the function (e.g. SUM) that's being used by the data value, but it will use the same function on all these columns. The Pivot Table contains some meaningless data, such as sum of Date and columns full of zeros where the database columns contain text. To avoid this, you can rearrange your database columns, and then use data

ranges that only include the columns that you want to total. If possible, move your data to a single worksheet, or store it in a database, such as MS Access, and you'll have more flexibility in creating the pivot table. Or, you can create named ranges in an Excel file, and use MS Query to combine the data. There are sample files here: http://www.contextures.com/excelfiles.html#PT0007

1. Pivot Tables -- Dynamic Data Source 2. Pivot Tables -- Data Field Layout 3. Pivot Tables -- Show and Hide Items 4. Pivot Tables -- Clear Old Items 5. Pivot Tables -- Field Settings 6. Pivot Tables -- GetPivotData 7. Pivot Tables -- Grouping Data 8. Pivot Tables -- Multiple Consolidation Ranges 9. Pivot Tables -- Printing 10. Pivot Tables -- Custom Calculations 11. Pivot Tables -- Pivot Cache 12. Pivot Tables -- Protection 13. Pivot Tables -- Grand Totals

Excel -- Pivot Tables -- Pivot Cache


1. 2. 3. 4.
Show the Pivot Table's CacheIndex Show the Pivot Cache Memory Used Show the Pivot Cache Record Count Change the Pivot Cache

Download the zipped sample file


Amazon.com

Show the Pivot Table's CacheIndex You can display a pivot table's CacheIndex number by using the following User Defined Function. Store the function code in a worksheet module. Then, on the worksheet, enter the formula: =ShowCacheIndex(A3) replacing A3 with a cell in your pivot table.
Function ShowCacheIndex(rngPT As Range) As Long ShowCacheIndex = rngPT.PivotTable.CacheIndex End Function

Show the Pivot Cache Memory Used

You can display the memory used by a pivot cache, by using the following User Defined Function. Store the function code in a worksheet module. Then, on the worksheet, enter the formula: =GetMemory(A3)/1000 replacing A3 with a cell in your pivot table. The result is displayed in kilobytes.
Function GetMemory(rngPT As Range) As Long Dim pt As PivotTable Set pt = rngPT.PivotTable GetMemory = ActiveWorkbook _ .PivotCaches(pt.CacheIndex).MemoryUsed End Function

Show the Pivot Cache Record Count You can display the number of records in a pivot cache, by using the following User Defined Function. Store the function code in a worksheet module. Then, on the worksheet, enter the formula: =GetRecords(A3) replacing A3 with a cell in your pivot table.
Function GetRecords(rngPT As Range) As Long Dim pt As PivotTable Set pt = rngPT.PivotTable GetRecords = ActiveWorkbook _ .PivotCaches(pt.CacheIndex).RecordCount End Function

Change the Pivot Cache If you have created several pivot tables in a workbook, you may find it more efficient to use the same pivot cache for all the pivot tables. The following code will change the pivot cache for each pivot table in the workbook.
Sub ChangePivotCache() 'change pivot cache for all pivot tables in workbook Dim pt As PivotTable Dim wks As Worksheet For Each wks In ActiveWorkbook.Worksheets For Each pt In wks.PivotTables pt.CacheIndex = Sheets("Pivot").PivotTables(1).CacheIndex Next pt Next wks End Sub

Excel -- Pivot Tables -- Grouping Data


1. 2. 3. 4. Grouping Dates Grouping Dates by Week Problems when Grouping Data Count Unique Items

Download the zipped sample file

Amazon.com

In a Pivot Table, you can group the items in a Row or Column field. For example, items in a date field can be grouped by month, and items in a number field can be grouped by tens. Grouping Dates To group the items in a Date field 1. Right-click the Date field button. 2. Choose Group and Show Detail | Group 3. In the Grouping dialog box, select one or more options from the 'By' list. 4. To limit the dates that are grouped, you can set a Start and End date, by typing the dates in the 'Starting at' and 'Ending at' boxes 5. Click OK

Grouping Dates by Week To group the items in a Date field by week 1. Right-click the Date field button. 2. Choose Group and Show Detail | Group 3. In the Grouping dialog box, select Days from the 'By' list. 4. For 'Number of days', select 7 5. The week range is determined by the date in the 'Starting at' box, so adjust this if necessary. In the example at right, December 29, 2003 (a Monday), was entered as the starting date. 6. Click OK Problems when Grouping Data If you try to group a date or field, you may see an error message that says, "Cannot group that selection." This problem usually occurs when the field contains records with a blank date/number field, or text in a date/number field. To fix the problem

For blank cells, fill in the date/number (use a dummy date/number if necessary). If there is text in the date/number field, remove it. If numbers are being recognized as text, use one of the techniques shown here to change them.

If you don't have blank cells or text in the date column, there may be a grouped field left over from the previous time that you grouped the data. 1. Check the field list, to see if there's a second copy of the date field, e.g. Date2. 2. If there is, add it to the row area, and ungroup it. 3. Then, you should be able to group the date field again. Count Unique Items In a pivot table, you may want to know how many unique customers placed an order for an item, instead of how many orders were placed. A pivot table won't calculate a unique count. However, you could add a column to the database, then add that

field to the pivottable. For example, to count the unique occurences of a Customer/Item order, add a column to your database, with the heading 'CustItem' In the first data row, enter a formula that refers to the customer and item columns. For example:

=IF(SUMPRODUCT(($A$2:$A2=A2)*($C$2:$C2=C2))>1,0,1) Copy the formula down to all rows in the database. Then, add the field to the data area of the pivot table. In this example, you can see that nine unique customers placed an order for binders, and there were 14 orders for binders.

Excel -- Pivot Tables -- Pivot Play PLUS Add-In


Thanks to Ron Coderre, who created this add-in. If your Pivot or Query Table is based on an External Data Query, Pivot Play PLUS was built to help you easily edit the Connection String to the data source and the Query itself. It also contains a handful of other features to help you manage your pivot and query tables in Excel 2002 and Excel 2003. Pivot Play Add-In Features General Usage Processing Options Data Source Settings Global Settings About the Developer Download Pivot Play PLUS To download the add-in file click this link: PivotPlayPLUS.zip
(for Excel 2002 and Excel 2003 only)

Install Pivot Play PLUS Installation Instructions

General Usage The Main Page (see illustration below) opens with a list of all Pivot and Query Tables that are on the active worksheet (along with key information about each of those tables). If a cell within one of those tables is selected when Pivot Play PLUS is

engaged, that table will be the default item selected on the list. Whenever a listed table is selected, additional information about that pivot table displays in the lower section of the Main Page. If the table data is based on an External Data Source, the Connection and Query information will be displayed and the Edit Settings button will be visible. Otherwise, a message that the source is not based on external data displays. To change the Connection Info or Query Info, click the Edit Conn/Qry Settings button. to open the Edit Settings For page.

Processing Options When a table from the list is selected, one or more option buttons, depending on whether the selected item is a Pivot Table or a Query Table. Each button's text indicates its functionality:

Refresh Data: Retrieves the latest data into the Pivot or Query Table.

Rename: allows you to give the selected Table a more descriptive name. Clear Invalid Field Names: removes dropdown list items that have no representation in the source data. (Pivot Tables ONLY).

Data Source Settings Clicking on the Edit Settings button opens a window displaying the Connection and Query details. Use this page to:

Edit the Connection Settings to the data source. The upper section of the page displays the current Connection settings. This is where you change the location of the data source and any other Connection String settings. Edit the Query Settings that extract data into the pivot cache. The lower section of the page displays the current query settings. Edit the SQL in this section.

An additional feature in this section is the Read Query From a Cell button, which allows you to select a single cell in the workbook that contains the SQL to be used by the Pivot or Query Table. That reference can be a cell reference or a named range. In either case, the contents of the cell are read and written into the Table settings; the Table itself is NOT linked to the cell Finally, the Connection Settings and Query Settings sections have buttons to restore their respective settings to the original values. NOTE: If the edited settings prove to be invalid when saving, you may continue editing the them or click the Restore button see the original values.

Global Settings The Turn GetPivotData On/Off button toggles Excel's automatic GetPivotData function generation on/off. The Reset Pivot Play PLUS Startup Settings button returns the Pivot Play StartUp options to their defaults. This includes displaying the Pivot Play splash screen upon opening. About the Developer When he's not sailing, Ron Coderre is a Business Systems Analyst and Application Developer at Teradyne, Inc. in Boston, where he works within the Finance organization to provide extensible, automated, process re-engineering solutions targeted at increasing the productivity of financial analysts and reducing analytical task duration. Inherent in his finished products are intuitive user interfaces, accurate data, the ability to easily adjust data scenarios, and publication-ready reports. Ron is also an Ron Coderre Essbase expert and provides technical training. To install the Add-in: 1. Download the PivotPlayPLUS.zip file 2. Unzip the file 3. Save the PivotPlayPLUS.xla file in your Microsoft\Addins folder. For example, in Windows XP, this might be: C:\Documents and Settings\Contextures\Application Data\Microsoft\AddIns (If you have previously installed the PivotPlay.xla add-in..Delete that file) 4. Open Excel 5. Choose Tools | Add-Ins 6. Click the Browse button 7. Find and select the PivotPlayPLUS.xla add-in 8. Click OK, click OK 9. A Pivot Play PLUS command will appear on the Data menu.

No Help is available for the add-in. If you have comments or suggestions, please contact ddalgleish@contextures.com

Excel -- Names -- Naming Ranges


Name a Range -- Name Box Create a Dynamic Range Name a Range - Name Box 1. 2. 3. 4. Select the cell(s) to be named Click in the Name box, to the left of the formula bar Type a one-word name for the list, e.g. FruitList. Press the Enter key.

After naming the range, you can select its name in the Name Box dropdown list, to select the range on the worksheet. You can also use names in formulas. For example: =SUM(JanSales) =TotalSales * TaxRate To view the steps in a short video, click here.

Create a Dynamic Range

You can use a dynamic formula to define a range. As new items are added, the range will automatically expand. Note: Dynamic named ranges will not appear in the Name Box dropdown list. However, you can type the name in the Name Box, to select the range on the worksheet. 1. Choose Insert>Name>Define 2. Type a name for the range, e.g. NameList

3. In the Refers To box, enter an Offset formula that defines the range size, based on the number of items in the column, e.g.: =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),1) In this example, the list is on Sheet1, starting in cell A1 The arguments used in this Offset function are: 1. Reference cell: Sheet1!$A$1 2. Rows to offset: 0 3. Columns to offset: 0 4. Number of Rows: COUNTA(Sheet1!$A:$A) 5. Number of Columns: 1 Note: for a dynamic number of columns, replace the 1 with: COUNTA(Sheet1!$1:$1) 4. Click OK 1. Names -- Naming Ranges

Excel -- Names -- Use Range Names in Formulas


Create a Table Create the first Dynamic Range Create the remaining Dynamic Ranges Create the Date Range selection cells Create the Summary formulas Create the Chart Download the zipped sample file

Test the Chart You can use a dynamic formula to define a range. As new items are added, the range will automatically expand. In this example, dynamic range names are used in formulas that summarize a list of sales records, and a chart is based on the result. When new records are added, or a different date range is selected, the chart is immediately updated.

Create a Table 1. 2. 3. 4. In a new workbook, delete all except two worksheets. Rename Sheet1 as SalesData Rename Sheet2 as Chart On the SalesData sheet, in cells A1:D1, add the headings, Date, Item, Colour, Units, as shown at the right.

5. Enter sample data in each column, or use the data in the zipped sample file. Create the first Dynamic Range A dynamic range will be created for the Date column. 1. Choose Insert | Name | Define 2. Type a name for the first range -- DateList 3. In the Refers To box, enter an Offset formula that defines the range size, based on the count of numbers in the Date column: =OFFSET(SalesData!$A$2,0,0,COUNT(SalesData!$A: $A),1) The arguments used in this Offset function are: 1. Reference cell: SalesData!$A$2 2. Rows to offset: 0 3. Columns to offset: 0 4. Number of Rows: COUNT(SalesData!$A:$A) 5. Number of Columns: 1 4. Click the Add button Create the remaining Dynamic Ranges The remaining dynamic ranges will be based on the DateList range. 1. Type a name for the next range -- ColourList 2. In the Refers To box, enter an Offset formula that refers to the DateList range: =OFFSET(DateList,0,2) The arguments used in this Offset function are:

1. Reference range: DateList 2. Rows to offset: 0 3. Columns to offset: 2 3. Click the Add button 4. Type a name for the next range -- UnitsList 5. In the Refers To box, enter an Offset formula that refers to the DateList range: =OFFSET(DateList,0,3) The arguments used in this Offset function are: 1. Reference range: DateList 2. Rows to offset: 0 3. Columns to offset: 3 6. Click the OK button Create the Date Range selection cells Use Data Validation to create dropdown lists for the chart start and end dates. 1. 2. 3. 4. 5. 6. 7. On the Chart sheet, select cells C2 and E2. Choose Data | Validation From the Allow dropdown, choose List In the Source box, type: =DateList Click OK Add a border to the cells, to highlight them. Select a sample date in each list, to be used in the Summary formulas.

8. Format the dates as desired (Format | Cells, Number tab) Create the Summary formulas Use the SUMPRODUCT function to total the sales for each colour. 1. On the Chart sheet, in cells B15:B18, type the list of colours sold. 2. In cell C15, enter the following formula: =SUMPRODUCT(--(ColourList=B15),(UnitsList),-(DateList>=$C$2),--(DateList<=$E$2)) 3. Copy the formula down to row 18. Create the Chart Create a chart from the summary list. 1. 2. 3. 4. On the Chart sheet, select cells B15:C18. On the toolbar, click the Chart Wizard button Create a column chart from the data Remove the chart legend, and adjust the chart size so it fits in the space between the date selection cells, and the summary list. 5. Click on the series to select it 6. Click on the Red column, to select it. 7. Double-click on the Red column, to open the

Format Data Point dialog box 8. For Area, select the red colour, then click the OK button. 9. Double-click on each of the remaining columns, and colour them.

Test the Chart 1. From the Date Range selection cells, select different dates. 2. The chart should update immediately, to reflect the new date range. For more information on Excel Charts, see Jon Peltier's site. 1. Names -- Naming Ranges 2. Names -- Using Names in Formulas Download the zipped sample file

Excel -- Sample Data

Download zipped sample workbook

Below is the sample data table used for many of my newsgroup and web site examples. You can select the data, and copy it for use in your own tests. Or download the data in an Excel file, by clicking the link above. And here's a chart that Dick Kusleika made from this data, using Widgenie. Date 1/6/07 1/23/07 2/9/07 2/26/07 3/15/07 4/1/07 4/18/07 5/5/07 5/22/07 6/8/07 6/25/07 7/12/07 7/29/07 8/15/07 Region Quebec Ontario Ontario Ontario Alberta Quebec Ontario Ontario Alberta Quebec Ontario Quebec Quebec Quebec Rep Jones Kivell Jardine Gill Sorvino Jones Andrews Jardine Thompson Jones Morgan Howard Parent Jones Item Pencil Binder Pencil Pen Pencil Binder Pencil Pencil Pencil Binder Pencil Binder Binder Pencil Units Cost Total 95 $1.99 $189.05 50 $19.99 $999.50 36 $4.99 $179.64 27 $19.99 $539.73 56 $2.99 $167.44 60 $4.99 $299.40 75 $1.99 $149.25 90 $4.99 $449.10 32 $1.99 $63.68 60 $8.99 $539.40 90 $4.99 $449.10 29 $1.99 $57.71 81 $19.99 $1,619.19 35 $4.99 $174.65

9/1/07 9/18/07 10/5/07 10/22/07 11/8/07 11/25/07 12/12/07 12/29/07 1/15/08 2/1/08 2/18/08 3/7/08 3/24/08 4/10/08 4/27/08 5/14/08 5/31/08 6/17/08 7/4/08 7/21/08 8/7/08 8/24/08 9/10/08 9/27/08 10/14/08 10/31/08 11/17/08 12/4/08 12/21/08 Top

Ontario Quebec Ontario Quebec Quebec Ontario Ontario Quebec Ontario Ontario Quebec Alberta Ontario Ontario Quebec Ontario Ontario Ontario Quebec Ontario Ontario Alberta Ontario Alberta Alberta Ontario Ontario Ontario Ontario

Smith Jones Morgan Jones Parent Kivell Smith Parent Gill Smith Jones Sorvino Jardine Andrews Howard Gill Gill Kivell Jones Morgan Kivell Sorvino Gill Sorvino Thompson Andrews Jardine Jardine Andrews

Desk Pen Set Binder Pen Pen Pen Set Pencil Pen Set Binder Binder Binder Binder Pen Set Pencil Pen Pencil Binder Desk Pen Set Pen Set Pen Set Desk Pencil Pen Binder Pencil Binder Binder Binder

2 $125.00 16 $15.99 28 $8.99 64 $8.99 15 $19.99 96 $4.99 67 $1.29 74 $15.99 46 $8.99 87 $15.00 4 $4.99 7 $19.99 50 $4.99 66 $1.99 96 $4.99 53 $1.29 80 $8.99 5 $125.00 62 $4.99 55 $12.49 42 $23.95 3 $275.00 7 $1.29 76 $1.99 57 $19.99 14 $1.29 11 $4.99 94 $19.99 28 $4.99

$250.00 $255.84 $251.72 $575.36 $299.85 $479.04 $86.43 $1,183.26 $413.54 $1,305.00 $19.96 $139.93 $249.50 $131.34 $479.04 $68.37 $719.20 $625.00 $309.38 $686.95 $1,005.90 $825.00 $9.03 $151.24 $1,139.43 $18.06 $54.89 $1,879.06 $139.72

Excel -- Scenarios -- Automatically Show Scenario


Create a Dropdown List of Scenarios Add the Event Code Test the Code

You can use Scenarios to store several versions of the data in a worksheet. To make them easier to use, you can use programming to automatically show the selected Scenario. This example will use the Scenarios created here: Scenarios -- Create and Show Download the zipped sample starter file Create a Dropdown List of Scenarios To view a Scenario, you can choose Tools | Scenarios, then select a Scenario, click the Show button, and close the Scenario Manager dialog box. To make it easier to switch between Scenarios, you can create a dropdown list of Scenarios, and use event code to show the selected Scenario. Note: This example will only work in Excel 2000, or later versions. Create a list of Scenarios 1. On the Insert menu, choose Worksheet 2. Name the new sheet as Lists 3. Starting in cell A1, type the heading, and Scenario names, as shown at right.

Name the list of Scenarios The list will be easier to maintain if it's a dynamic named range. To create the named range: 1. On the Lists worksheet, select cell A1 2. Choose Insert | Name | Define 3. For Names in Workbook, type: ScenarioList 4. For Refers to, type the following formula: =OFFSET(Lists!$A$1,1,0,COUNTA(Lists!$A:$A)-1,1) 5. Click OK

Create the dropdown list 1. 2. 3. 4. On the Budget worksheet, select cell B1 Choose Data | Validation From the Allow dropdown, choose List In the Source box, type: =ScenarioList

5. Click OK

Add the Event Code 1. Right-click on the Budget sheet tab 2. Choose View Code 3. From the Object dropdown, at the top left, choose Worksheet. 4. From the Procedure dropdown, at the top right, choose Change. 5. Where the cursor is flashing, enter the following code:
If Target.Address = "$B$1" Then ActiveSheet.Scenarios(Target.Value).Show End If

6. Choose File | Close and Return to Microsoft Excel Test the Code 1. On the Budget worksheet, select an item from the dropdown list in cell B1. 2. That Scenario will be displayed. 3. Close and save the workbook. Note: When opening the workbook, you will have to enable macros in order to use this code. Download the zipped sample completed file 1. Scenarios -- Create and Show 2. Scenarios -- Scenario Summaries 3. Scenarios -- Automatically Show Scenario 4. Scenarios -- Programming
Download the zipped sample file

Excel -- Scenarios -- Create and Show


Set up the Worksheet Create the first Scenario

Create the second Scenario Show a Scenario

You can use Scenarios to store several versions of the data in a worksheet. For example, when preparing a budget, the Marketing and Finance departments may have different forecasts for sales. You can store each forecast as a Scenario, print them separately, or compare them side-byside.

Set up the Worksheet Although scenarios can be complex, a simple example is used here. 1. Delete all sheets except Sheet1 2. Rename Sheet1 as Budget 3. On the Budget sheet, enter the Finance budget, as shown at right 4. Name the following cells (there are Naming instructions here: Name a Range). Naming the cells is not required, but will make it easier to manage the scenarios, and read the reports: o Name cell B1 as Dept o Name cell B3 as Sales o Name cell B4 as Expenses o Name cell B6 as Profit 5. In cell B6, enter the following formula: =Sales - Expenses Create the First Scenario 1. From the Tools menu, choose Scenarios. 2. In the Scenario Manager, click the Add button 3. Type name for the Scenario. For this example, use Finance. 4. Press the Tab key, to move to the Changing cells box 5. On the worksheet, select cells B1 6. Hold the Ctrl key, and select cells B3:B4 Note: There is a limit of 32 changing cells 7. Press the Tab key, to move to the Comment box 8. (optional) Enter a comment that describes the scenario. 9. Click the OK button
1 2 3 5 6

Budget 2006

Finance $ 3,500,000 $ 2,750,000 =Sales - Expenses

Sales 4 Expenses Profit

10. The Scenario Values dialog box opens, with a box for each changing cell. 11. You could modify these values, but in this example they contain the values currently on the worksheet, and don't need to be changed. 12. Click the OK button, to return to the Scenario Manager. 13. Click the Close button, to return to the worksheet Create the Second Scenario 1. To prepare for the Marketing scenario, change the values in cells B1, B3 and B4, as shown at right 2. From the Tools menu, choose Scenarios. 3. In the Scenario Manager, click the Add button 4. Type name for the second Scenario. For this example, use Marketing. 5. Press the Tab key, to move to the Changing cells box 6. On the worksheet, select cells B3:B4 7. Press the Tab key, to move to the Comment box 8. (optional) Enter a comment that describes the scenario. 9. Click the OK button 10. The Scenario Values dialog box opens, with a box for each changing cell. 11. Click the OK button, to return to the Scenario Manager. 12. Click the Close button, to return to the worksheet Show a Scenario Once you have created Scenarios, you can show them. In this example, the Marketing scenario is currently visible. To change to a different scenario: 1. Fom the Tools menu, choose Scenarios 2. In the list of Scenarios, select Finance 3. Click the Show button 4. Click the Close button. 1. Scenarios -- Create and Show 2. Scenarios -- Scenario Summaries 3. Scenarios -- Automatically Show Scenarios 4. Scenarios -- Programming
Download the zipped sample file A 1 2 3 5 B

Budget 2006

Marketing $ 3,900,000 $ 2,450,000

Sales 4 Expenses

Contextures -- Excel Keyboard Shortcuts

Navigate cells

Select

Right..........Tab Start of worksheet..........Ctrl + Home End of worksheet ..........Ctrl + End Start of row..........Home Up/down one screen..........Page Up/ Down

Column..........Ctrl + space Row..........Shift + space Entire worksheet..........Ctrl + A

Work in a range

Standard actions

Activate menus..........F10 Save..........Ctrl + S Print..........Ctrl + P New workbook..........Ctrl + N Open..........Ctrl + O Copy..........Ctrl + C Cut..........Ctrl + X Paste..........Enter

Select current range..........Ctrl + * Move to range border..........Ctrl + arrow Move down..........Enter Move up..........Shift + Enter Move right..........Tab Move left..........Shift + Tab Switch focus to worksheet from range selector in dialog box....F6

Edit worksheet

Copy data

Edit cell..........F2 Insert..........Ctrl + + Delete..........Ctrl + -

Fill down..........Ctrl + D Fill right..........Ctrl + R Copy formula above..........Ctrl + ' Copy value above..........Ctrl + "

Complete actions

Format Numbers

Repeat last action..........F4 Todays date..........Ctrl + ; Chart selected data..........F11

General..........Ctrl + Shift + ~ Currency..........Ctrl + Shift + $ Percentage..........Ctrl + Shift + % Date (d, m, y)..........Ctrl + Shift + #

Apply Formatting

Format cells..........Ctrl + 1 Remove borders..........Ctrl + Shift + _

Excel -- Sorting Data -- The Basics


Sort by One Column Sort by Two or Three Columns Using the Sort Buttons Sort by Four or More Columns

Sort by One Column 1. Select all the cells in the list. This is the safest approach to sorting. In most cases, you can select one cell and Excel will correctly detect the rest of the list -- but it's not 100% certain. Some of the data may be missed. 2. Choose Data>Sort 3. From the Sort by dropdown, select the column you want to sort. Note: If the dropdown is showing Column letters instead of headings, change the setting for My list has, from No header row to Header row. 4. Select to sort in Ascending or Descending order 5. Click OK Sort by Two or Three Columns 1. Select all the cells in the list. 2. Choose Data>Sort 3. From the Sort by dropdown, select the first column you want to sort. 4. Select to sort in Ascending or Descending order 5. From the Then by dropdown, select the second column you want to sort. 6. Select to sort in Ascending or Descending order 7. From the Then by dropdown, select the third column you want to sort. 8. Select to sort in Ascending or Descending order 9. Click OK Using the Sort Buttons In Excel, it's easy to sort your data by using the Sort buttons on the toolbar. But, be careful, or one column may be sorted, while others are not. 1. Select one cell in the column you want to sort. 2. Click Sort Ascending (A to Z, smallest to largest) or Sort Descending (Z to A, largest to smallest) 3. Before you do anything else, check the data, to ensure that the rows have sorted correctly. If things look wrong, click the Undo button on the toolbar.

Sort by Four or More Columns Occasionally, you may need to sort by more than three columns. For example, in a mailing list, you may want to sort by Country, Region, City, and Name. To do this, you can sort the list multiple times, starting with the least important sort. In the mailing list, there are four columns to sort. Name and City are the least important fields in the sorting process, so they can be sorted first. 1. 2. 3. 4. 5. Select all the cells in the list. Choose Data>Sort From the Sort by dropdown, select City. From the Then by dropdown, select Name. Click OK

Excel will retain what it can of this sort while you sort by the remaining fields. 1. With all the cells still selected, choose Data>Sort 2. From the Sort by dropdown, select Country. 3. From the Then by dropdown, select Region. 4. Click OK 1. Sorting Data -- Basics 2. Sorting Data -- Programming

Excel -- Worksheet Functions -- Sum Cells


Sum a range of cells -- SUM Sum a range of cells -- OFFSET Grand Total a range of cells Sum cells that match criteria -- SUMIF - Match criterion exactly - Match criterion in a string - Match criterion using operator Sum cells that match multiple criteria -- SUMPRODUCT Sum the Top 5 Numbers in a List Sum the Numbers in a Filtered List

AutoSum Download zipped sample workbook

Sum a range of cells -- SUM The SUM function will add the numbers in a range of cells. Its syntax is: =SUM(number1, number2,...number30). The arguments (e.g. number1) can be cell references, or typed into the formula. The following example uses one argument -- a reference to cells A1:A4. 1. Select the blank cell in the row below the cells that you want to sum, cell A5 in this example. 2. Click the AutoSum button on the Standard toolbar A SUM formula will appear in the active cell 3. Press the Enter key to complete the entry.
o

Note: Instead of using the AutoSum button, you could type the formula into the cell. Sum a range of cells -- OFFSET If you insert a row directly above the SUM formula in the previous example, the new row may not be included in the SUM. It may continue to sum cells A1:A4, and ignore A5. To ensure that new rows are included in the total, you can use the OFFSET function. 1. Select cell A5. 2. Enter the following formula: =SUM(A1:OFFSET(A5,-1,0)) 3. Press the Enter key to complete the entry. 4. Insert a row above row 5 5. Type a number in cell A5, and it will be included in the total in cell A6 Grand Total a range of cells You can calculate row totals, column totals, and a grand total for a range of cell, all in one step. 1. Select the range of cells, and the blank row below the range, and the blank cells in the column to the right (cells A1:D5 in the example at right) 2. Click the AutoSum button on the Standard toolbar
o

A SUM formula will be entered for each Total

Sum cells that match criteria -- SUMIF Match criterion exactly You can calculate a total for rows that meet a specific criterion. In this example only the rows with Pen orders will be included in the total. 1. 2. 3. 4. 5. 6. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked Type a comma, to separate the arguments Type the criterion. In this example, you're checking for text, so type the word in double quotes: "Pen" Note: upper and lower case are treated equally Type a comma, to separate the arguments Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed The completed formula is: =SUMIF(A2:A10,"Active",B2:B10)

7. 8. 9.

10. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10, B12, B2:B10) if cell B12 contained the text pen.

Match criterion in a string You can add cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be summed, because they contain the string "pen". 1. Select the cell in which you want to see the total (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: SUMIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters: "*Pen*" Note: upper and lower case are treated equally 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed 9. Type a closing bracket. The completed formula is: =SUMIF(A2:A10,"*Pen*",B2:B10) 10. Press the Enter key to complete the entry 11. The result will be 53, the total of rows that contain the string, "Pen" Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10,"*" & B12 & "*",B2:B10) if cell B12 contained the text pen.

Criterion and operator You can use an operator with a criterion. In this example only the rows where the number of sales reps is greater than or equal to ten will be included in the total. 1. 2. 3. 4. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells B2:B10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for rows where the number of visits is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes. 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum 9. Type a closing bracket. The completed formula is: =SUMIF(B2:B10,">=10",C2:C10) 10. Press the Enter key to complete the entry 11. The result will be 183, the total of rows with ten or more sales reps. Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(B2:B10,">=" & B12,C2:C10) if cell B12 contained the number 10. Sum cells that match multiple criteria -- SUMPRODUCT Match multiple criteria You can calculate a total for rows that meet two or more criteria. In this example only the rows where the status is "Active" and the number of visits is greater than or equal to ten will be included in the total.

1. 2. 3. 4.

Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMPRODUCT(--( Select the cells that contain the values to check for the first criterion. In this example, cells A2:A6 will be checked 5. Type the first criterion: ="Active" 6. Type ),--( 7. Select the cells that contain the values to check for the second criterion. In this example, cells B2:B6 will be checked 8. Type the second criterion: >=10 9. Type ),--( 10. Select the cells that contain the values to sum. In this example, cells C2:C6 will be summed 11. Finish with closing brackets: )) 12. The completed formula is: =SUMPRODUCT(--(A2:A6="Active"), --(B2:B6>=10),-(C2:C6)) 13. Press the Enter key to complete the entry

Sum the Top 5 Numbers in a List Use the SUM and LARGE functions together, to add the largest numbers in the list.

Version 1 -- Few Top Numbers


If a few numbers are to be summed, e.g. top 3, you can type the numbers into the formula. For example: =SUM(LARGE(A1:A7,{1,2,3})) The result is 70+60+50 = 180 Note: The second 50 is not included in the result, even though it is tied for 3rd place.

Version 2 -- Many Top Numbers


If many top numbers are to be summed you can include the INDIRECT function in the formula. In the INDIRECT function, use row numbers that represent the numbers you want to include. In this example, rows 1:10 are used, so the top 10 numbers in the referenced range will be summed. 1. Type the formula: =SUM(LARGE(A1:A50,ROW(INDIRECT("1:10")))) 2. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter

Version 3 -- Variable Top Numbers


If a variable number of top numbers are to be summed you can include the INDIRECT function in the formula, as shown above, and refer to a cell that holds the variable.. 1. In cell C1, type the number of top cells, e.g. 10 2. Type the formula: =SUM(LARGE(A1:A7,ROW(INDIRECT("1:"&C1)))) 3. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter Sum the Numbers in a Filtered List After you filter the rows in a list, you can use the SUBTOTAL function to sum the numbers in the visible rows. 1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics 2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders. 3. Select the cell immediately below the column you want to sum. 4. Click the AutoSum button on the Excel's Standard toolbar. o If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button. 5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column o The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. There is a 9 in this example, which tells Excel to SUM the numbers.

Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list. 6. Press the Enter key to complete the formula entry.
o

Note: In Excel 2003, you can use the formula: =SUBTOTAL(109,B2:B9) to subtotal visible cells in a range where rows have been manually hidden, or filtered. Download zipped sample workbook

Worksheet Functions -- Sum Cells Worksheet Functions -- VLOOKUP Worksheet Functions -- INDEX / MATCH Worksheet Functions -- Count Cells Worksheet Functions -- INDIRECT

Excel -- Worksheet Functions -- Sum Cells


Sum a range of cells -- SUM Sum a range of cells -- OFFSET Grand Total a range of cells Sum cells that match criteria -- SUMIF - Match criterion exactly - Match criterion in a string - Match criterion using operator Sum cells that match multiple criteria -- SUMPRODUCT Sum the Top 5 Numbers in a List Sum the Numbers in a Filtered List

AutoSum Download zipped sample workbook

Sum a range of cells -- SUM The SUM function will add the numbers in a range of cells. Its syntax is: =SUM(number1, number2,...number30). The arguments (e.g. number1) can be cell references, or typed into the formula. The following example uses one argument -- a reference to cells A1:A4. 1. Select the blank cell in the row below the cells that you want to sum, cell A5 in this example. 2. Click the AutoSum button on the Standard toolbar A SUM formula will appear in the active cell 3. Press the Enter key to complete the entry.
o

Note: Instead of using the AutoSum button, you could type the formula into the cell. Sum a range of cells -- OFFSET If you insert a row directly above the SUM formula in the previous example, the new row may not be included in the SUM. It may continue to sum cells A1:A4, and ignore A5. To ensure that new rows are included in the total, you can use the OFFSET function. 1. Select cell A5. 2. Enter the following formula: =SUM(A1:OFFSET(A5,-1,0)) 3. Press the Enter key to complete the entry. 4. Insert a row above row 5 5. Type a number in cell A5, and it will be included in the total in cell A6 Grand Total a range of cells You can calculate row totals, column totals, and a grand total for a range of cell, all in one step. 1. Select the range of cells, and the blank row below the range, and the blank cells in the column to the right (cells A1:D5 in the example at right) 2. Click the AutoSum button on the Standard toolbar
o

A SUM formula will be entered for each Total

Sum cells that match criteria -- SUMIF Match criterion exactly You can calculate a total for rows that meet a specific criterion. In this example only the rows with Pen orders will be included in the total. 1. 2. 3. 4. 5. 6. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked Type a comma, to separate the arguments Type the criterion. In this example, you're checking for text, so type the word in double quotes: "Pen" Note: upper and lower case are treated equally Type a comma, to separate the arguments Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed The completed formula is: =SUMIF(A2:A10,"Active",B2:B10)

7. 8. 9.

10. Press the Enter key to complete the entry Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10, B12, B2:B10) if cell B12 contained the text pen.

Match criterion in a string You can add cells that contain a criterion as part of the cell's contents. In this example all Pen, Gel Pen, and Pencil orders will be summed, because they contain the string "pen". 1. Select the cell in which you want to see the total (cell A12 in this example) 2. Type an equal sign (=) to start the formula 3. Type: SUMIF( 4. Select the cells that contain the values to check for the criterion. In this example, cells A2:A10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for text, so type the word in double quotes, with one or more asterisk (*) wildcard characters: "*Pen*" Note: upper and lower case are treated equally 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum. In this example, cells B2:B10 will be summed 9. Type a closing bracket. The completed formula is: =SUMIF(A2:A10,"*Pen*",B2:B10) 10. Press the Enter key to complete the entry 11. The result will be 53, the total of rows that contain the string, "Pen" Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(A2:A10,"*" & B12 & "*",B2:B10) if cell B12 contained the text pen.

Criterion and operator You can use an operator with a criterion. In this example only the rows where the number of sales reps is greater than or equal to ten will be included in the total. 1. 2. 3. 4. Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMIF( Select the cells that contain the values to check for the criterion. In this example, cells B2:B10 will be checked 5. Type a comma, to separate the arguments 6. Type the criterion. In this example, you're checking for rows where the number of visits is greater than or equal to 10. The >= operator is used before the number, and the entire criterion is enclosed in double quotes. 7. Type a comma, to separate the arguments 8. Select the cells that contain the values to sum 9. Type a closing bracket. The completed formula is: =SUMIF(B2:B10,">=10",C2:C10) 10. Press the Enter key to complete the entry 11. The result will be 183, the total of rows with ten or more sales reps. Note: Instead of typing the criterion in a formula, you can refer to a cell. For example, the formula in step 9 above could be changed to: =SUMIF(B2:B10,">=" & B12,C2:C10) if cell B12 contained the number 10. Sum cells that match multiple criteria -- SUMPRODUCT Match multiple criteria You can calculate a total for rows that meet two or more criteria. In this example only the rows where the status is "Active" and the number of visits is greater than or equal to ten will be included in the total.

1. 2. 3. 4.

Select the cell in which you want to see the total Type an equal sign (=) to start the formula Type: SUMPRODUCT(--( Select the cells that contain the values to check for the first criterion. In this example, cells A2:A6 will be checked 5. Type the first criterion: ="Active" 6. Type ),--( 7. Select the cells that contain the values to check for the second criterion. In this example, cells B2:B6 will be checked 8. Type the second criterion: >=10 9. Type ),--( 10. Select the cells that contain the values to sum. In this example, cells C2:C6 will be summed 11. Finish with closing brackets: )) 12. The completed formula is: =SUMPRODUCT(--(A2:A6="Active"), --(B2:B6>=10),-(C2:C6)) 13. Press the Enter key to complete the entry

Sum the Top 5 Numbers in a List Use the SUM and LARGE functions together, to add the largest numbers in the list.

Version 1 -- Few Top Numbers


If a few numbers are to be summed, e.g. top 3, you can type the numbers into the formula. For example: =SUM(LARGE(A1:A7,{1,2,3})) The result is 70+60+50 = 180 Note: The second 50 is not included in the result, even though it is tied for 3rd place.

Version 2 -- Many Top Numbers


If many top numbers are to be summed you can include the INDIRECT function in the formula. In the INDIRECT function, use row numbers that represent the numbers you want to include. In this example, rows 1:10 are used, so the top 10 numbers in the referenced range will be summed. 1. Type the formula: =SUM(LARGE(A1:A50,ROW(INDIRECT("1:10")))) 2. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter

Version 3 -- Variable Top Numbers


If a variable number of top numbers are to be summed you can include the INDIRECT function in the formula, as shown above, and refer to a cell that holds the variable.. 1. In cell C1, type the number of top cells, e.g. 10 2. Type the formula: =SUM(LARGE(A1:A7,ROW(INDIRECT("1:"&C1)))) 3. This is an array formula, and must be array-entered. To do this, hold the Ctrl and Shift keys, and press Enter Sum the Numbers in a Filtered List After you filter the rows in a list, you can use the SUBTOTAL function to sum the numbers in the visible rows. 1. Apply an AutoFilter to the table. There are instructions here -- AutoFilter Basics 2. Filter at least one of the columns in the table. In this example, the first column has been filtered for Binders. 3. Select the cell immediately below the column you want to sum. 4. Click the AutoSum button on the Excel's Standard toolbar. o If you want the SUBTOTAL function in a cell other than the one directly below the filtered list, you can type the formula, instead of using the AutoSum button. 5. A SUBTOTAL formula will be automatically inserted, totalling the visible cells in the column o The first argument in the SUBTOTAL function is a function number, that specifies how the numbers should be calculated. There is a 9 in this example, which tells Excel to SUM the numbers.

Other function numbers can be used, such as 1 for AVERAGE, and 3 for COUNTA. Look in Excel's Help for a complete list. 6. Press the Enter key to complete the formula entry.
o

Note: In Excel 2003, you can use the formula: =SUBTOTAL(109,B2:B9) to subtotal visible cells in a range where rows have been manually hidden, or filtered. Download zipped sample workbook

Excel -- Data Entry -- Convert Text to Numbers


Convert with Paste Special Convert Dates with Replace All Convert with Text to Columns Convert Trailing Minus Signs Convert Trailing Minus Signs Programmatically Paste as CSV Convert Programmatically

If you copy data from another program, such as Microsoft Access, or from a text file, Excel may treat the numbers as text.* Calculations that use these numbers will be incorrect, as

in the SUM shown above. There are several methods that you can use to convert the text "numbers" to real numbers. Convert with Paste Special 1. Select a blank cell 2. Choose Edit>Copy 3. Select the cells that contain the numbers 4. Choose Edit>Paste Special 5. Select Add 6. Click OK 7. To apply number formatting, choose Format>Cells 8. On the Number tab, select the appropriate format, then click OK. Watch the Video View the steps described above, in a short video clip.

Convert Dates with Replace All If dates are formatted with slashes, such as 5/5/04, you can convert them to real dates by replacing the slashes. 1. Select the cells that contain the dates 2. Choose Edit>Replace 3. For Find what, type a forward slash: / 4. For Replace with, type a forward slash: / 5. Click Replace All 6. To apply date formatting, choose Format>Cells 7. On the Number tab, select a date format, then click OK.

Convert with Text to Columns 1. Select the cells that contain the numbers 2. Choose Data>Text to Columns 3. Click Finish Convert Trailing Minus Signs In Excel 2002, and later versions, imported numbers with trailing minus signs can be easily converted to negative numbers. 1. 2. 3. 4. 5. 6. Select the cells that contain the numbers Choose Data>Text to Columns To view the Trailing Minus setting, click Next, click Next In Step 3, click the Advanced button Check the box for 'Trailing minus for negative numbers', click OK Click Finish

Note: If 'Trailing minus for negative numbers' is checked, you can click Finish in Step 1 of the Text to Columns wizard.

You might also like