You are on page 1of 17

EXCEL 2010 HANDOUT

The VLOOKUP function


The VLOOKUP function looks up the value in the first column of the lookup table and returns the
correspondingvalue in a specified table column. The lookup table is arranged vertically (which explains the V in
the functions name). The syntax for the VLOOKUP function is VLOOKUP (lookup_value,
table_array,col_index_num,range_lookup)

The VLOOKUP functions arguments are as follows:


n lookup_value: The value to be looked up in the first column of the lookup table.
n table_array: The range that contains the lookup table.
n col_index_num: The column number within the table from which the matching value is returned.
n range_lookup: Optional. If TRUE or omitted, an approximate match is returned. (If an exact match is not found,
the next largest value that is less than lookup_valueis returned.) If FALSE, VLOOKUP will search for an exact
match. If VLOOKUP cant find an exact match, the function returns #N/A.

Work with the Sort Command


1. Select or click in the list of data you want to sort.
Select only a single column of data if you want to sort that columnindependently of the rest of the data.
2. Choose DataSort & Filter Sort. The Sort dialog boxopens.
3. If your data includes column headings, make sure theMy Data Has Headers option is checked. If the
datadoesnt include column headings, deselect the option.Excel does not include header rows in the sort process.
4. From the Sort By drop-down list, select the column bywhich you want to sort.
5. From the Sort On drop-down list, choose Values.
6. From the Order drop-down list, select how you want tosort the data:
Choose A to Z or Z to A to sort text values.
Choose Smallest to Largest or Largest to Smallest tosort numeric data.
Choose Oldest to Newest or Newest to Oldest to sortby dates.
7. Click OK.

Sort by Multiple Criteria


1. Select or click in the list of data you want to sort.
2. Choose DataSort & Filter Sort. The Sort dialog boxopens.
3. If your data includes column headings, make sure theMy Data Has Headers option is checked. If the
datadoesnt include column headings, deselect the option.Although the most common sort is by rows (top to
bottom), you canalso sort by columns (left to right). In the Sort dialog box, click theOptions button and then,
under the Orientation section, choose Sortleft to right. Finally, click OK.
4. Set up the primary sort criteria as in the previous section.
Excel sorts dates formatted with slashes such as 11/22/68, asnumeric data. Dates with the day or month spelled
out must be sorteddifferently. See the later section, Sort by Day, Month, or CustomList.
5. Click the Add Level button.
6. In the Then By section, select the secondary column youwant to sort by if two or more items are identical in
thefirst Sort By option.
7. Select how you want to sort the second data criteria.Repeat as needed.To delete an entry, select the sort entry
and choose Delete Level.You must keep at least one sort entry in the list.
8. Click OK. Excel performs the sort process.

1 Content by Experts of ADETC


Use Advanced Filtering

1. Make sure the AutoFilter is turned off (DataSort &FilterFilter).


2. Select the first for rows of the worksheet.
3. Choose HomeCellsInsertInsert Sheet Rows.
4. Select the database header row.
5. Choose HomeClipboardCopy or press Ctrl+C. Amarquee appears around the copied area.
6. Click cell A1, the first cell of the first blank row.
7. Choose HomeClipboardPaste, which copies theheader row of your database to the first blank row(Row 1).
You now have a criteria range ready to enterfilter selections.
8. In the first blank row of the criteria range, enter the datayou want to match. For example, if you want to
locateany entries for the state of California, type Californiaunder the State heading.
9. Enter any additional filter criteria:
Create an And filter: If you want Excel to find data that meets more than one restriction, enter the
desired additional criteria in another field on the firstcriteria row.
Create an Or filter: Enter the filter data on the secondrow of the criteria range.
10. Click any cell in the main part of the database.
11. Choose DataSort & FilterAdvanced. Excel displaysthe Advanced Filter dialog box.
12. Select the Filter the List, In Place option in the Actionssection.
13. Verify the database range in the List Range box.
14. Enter the criteria range. Excel provides two differentways to do this:
Type the criteria range including the header row, butnot any blank rows. the criteria range is A1: F2.
Be sure to specify only the rows that contain filtering information.If you include blank rows in your criteria range,
Excel includes themin the filtering process. The effect is that no data is filtered out, so all records are returned.
Click the Collapse button to the right of the CriteriaRange box and highlight the entire criteria range,
againincluding the header row but not any blank rows.Press Enter to return to the Advanced Filter dialog box.
15. Click OK. Excel places the results of your search in placeof your original database.
16. When youre ready to view all data records, chooseDataSort & FilterClear.

Create a PivotTable

1. Organize your data in a list, while keeping these points in mind:


Each column should contain only one type of data; for example, put dates in one column and values in another.
Make sure each column in the list has a headinglabel directly above the data. PivotTables use the column
headings asPivotTable fields.
Do not leave any blank rows between the data and therow headings and no blank columns within the data.
Avoid blank cells within the data. If you have duplicatedata, use the Copy command to replicate it in the blank
cells.
If you have more than one list on the same worksheet, make sure at least one blank column and one blankrow
separate them.
Remove any Excel-generated subtotals or grand totals in the data by choosing
DataOutlineSubtotalRemove All.
Plan the questions that determine how you want yourdata analyzed. For example, if your data is sales
information, perhaps you want to know your sales totals byregion or a specific salesperson, or even deeper such
asby both salesperson and by quarter.

2 Content by Experts of ADETC


2. Optionally, click any cell containing the data you wantto analyze.
3. Choose InsertTablesPivotTable. The CreatePivotTable dialog box appears.
4. Make a selection. Excel needs to know where your datawill come from:
Microsoft Excel list or database: This choice createsthe PivotTable from organized data in a Microsoft
Excel worksheet.
External data source. This choice creates a PivotTablefrom data stored in a non-Excel database.
5. Verify that Excel correctly identified your data range,including the headings. If not, specify the correct area
inthe Table/Range box .If the data is in another worksheet in the same workbook or a different saved workbook,
type the workbook and worksheet name like this: [workbookname] sheetname! range.
6. Choose whether to add the PivotTable to a new worksheetin your workbook or to another existing worksheet.If
you choose to add it to an existing worksheet,you must specify a cell location.
7. Click OK. Excel creates a new worksheet with a blankPivotTable along with PivotTable Field List, which contains
each field from your data range.
PivotTables contain three primary elements:
Rows: The Rows area displays your data vertically,with one item per row.
Columns: The Columns area displays the data horizontally,with one item per column.
Values: Data Fields summarize numerical data.
8. From the PivotTable Field List pane, click the check boxnext to the field you want categorized. For example,
ifyou want to determine how much each salespersonsold, select the Rep ID field. Excel automatically placeseach
unique item into the Pivot Table rows and displaysthe name in the Row Labels box in the Areas sectionlocated
beneath the field name list. Exceldisplays the name of each Sales Rep.
If you want the categorized field displayed horizontally insteadof vertically, drag the field to the Column Labels
box of the Areassection.
9. From the PivotTable Field List pane, select the field,such as Sales Amount, you want summarized and
performone of the following actions. Excel instantly takesthe data and adds the totals to create the summary
Click the check box next to the field.The PivotTable Field List indicates fields used in the PivotTable withbold
lettering. You dont have to use all the fields in the PivotTable,and you dont have to place fields in every area of
the PivotTable.
Drag the field to the Values area in the Areas section.If you drag a field to an incorrect area, uncheck the field
namecheck box or drag the field name out of the Areas section onto theExcel worksheet.
To delete a PivotTable, choose PivotTable Tools OptionsActionsSelectEntire PivotTable. Press the Delete
key. Optionally, deletethe entire worksheet.

To move a PivotTable to a different location, choose PivotTable Tools


OptionsMove PivotTable. In the resulting dialog box, specify orpoint to a new location for the current
PivotTable.
Select and Manage PivotTable Data
1. On the PivotTable, click the down arrow in the RowLabels heading section. A list of individual items, suchas
sales rep names, appears. The items that appear depend on the values you used in your data.
2. Remove the check mark next to any item you dont want included in the PivotTable.
3. Click OK. Only data for two specifically selected sales reps appears in the PivotTable.
To clear the filter, click the heading arrow and choose Clear Filter orcheck Select All.
4. Select any of the following methods to update thePivotTable with any changes made in the original data:
Choose PivotTable Tools OptionsDataRefresh.
Right-click anywhere on the PivotTable and chooseRefresh from the shortcut menu.
Make the PivotTable automatically refresh wheneveryou reopen the file by choosing PivotTable Tools

3 Content by Experts of ADETC


OptionsPivotTableOptions. From the Data tab ofthe PivotTable Options dialog box, select RefreshData When
Opening File.
5. Double-click any data value to display the specificdetails that comprise the data. In Figure 15-8 you seethe
detail for Sales Rep Charlene displayed on a separateworksheet.
You can safely delete the separate individual worksheet withoutaffecting the PivotTable.

Sort PivotTable Data


1. Click anywhere in the field you want to sort.
2. Choose PivotTable Tools Sort.Depending on the data type, the option may say Sort Smallest to
Largest or Sort A to Z.
3. Click a Sort button. The PivotTable data sorts accordingto your choice. Click the Sort button to display the Sort
by box.

Change the Calculation Type


1. Click anywhere in the subtotaled data field.
2. Choose PivotTable Tools OptionsActive FieldFieldSettings.
3. From the Summarize By list, select the function you wantto use. Choices include Sum, Count, Average, Max,
Min,Product, CountNums, StdDev, StdDevp, Var, and Varp.
4. Click OK. Excel re-summarizes the field based on the function you selected. The field title also changes toreflect
the selected function.

Rename a PivotTable Field


1. Click anywhere in the field data you want to rename.
2. Choose PivotTable Tools OptionsActive FieldFieldSettings. Optionally, click the field name in the PivotTable
and begin typinga new name. Press Enter when you are finished.
3. In the Custom Name box, type the new field name.
4. Click OK. Both the PivotTable field and the Field Listnames change.

Format PivotTable Values


1. Select the PivotTable field you want to modify.
2. Choose PivotTable Tools OptionsActive FieldFieldSettings.
3. From the Field Settings dialog box, click the NumberFormat button.
4. From the Format Cells dialog box select the Number format you want.
5. If applicable, select the number of decimal places youwant.
6. Click OK twice.

AutoFormat PivotTables
1. Choose PivotTable Tools DesignPivotTable Styles.
2. Click the More arrow. A gallery of PivotTable stylesappears
3. Select a format. Excel provides over 85 different predefined
PivotTable formats, or you can create your ownformat.
To remove the formatting, Choose PivotTable ToolsDesignPivotTable StylesMoreClear.

4 Content by Experts of ADETC


Group Data Together
1. Create a PivotTable.
2. Click in any cell of the field you want to group. A popularfield to group is a date field.
3. Choose PivotTable Tools OptionsGroupGroup Field.
4. From the Grouping dialog box, select the groupingoption you want to use. The options that appear dependon
the type of data you are grouping.
5. Click OK.

Generate Multilevel Totals


1. Create a Pivot Table .
2. To create a second summary level, drag the next fieldyou want to subtotal from the PivotTable Field List
ontothe desired PivotTable area, keeping these pointers inmind:
If you want to create a second category, such as byCountry and then by Salesman, drag the field into the Row
area. The field closest to the data is calledthe inner row (in this example, Invoice Date). The other field is called an
outer row (in this example, Salesperson). Excel displays data in the inner row under each of the outer row fields.
If you want to change the order of the inner andouter row fields, from the Area box, drag the field you want as
the outer row to the top of the box.
If you want to total additional fields, drag the fieldinto the Data area.You can add even more data fields to your
PivotTable. PivotTabledata fields are only limited by the amount of memory in yourcomputer.
If you want to sum different fields or if you want tocreate two different total types (such as count and sum, or
max and min), select a field you have alreadyused. Currently used fields are listed in bold type.
Click the minus sign to collapse a row heading suchas a particular salespersons name. Click the plus signto
expand the row again to see all the data.

Calculate a Percent of Totals


1. Add a second totals field and display the two fields sideby side.
2. Select the second totals field and choose PivotTableTools OptionsActive FieldField Settings.
3. Click the Show Values As tab and from the drop-downlist, then choose % of Column.Click OK.

Add Your Own Calculations


1. Choose PivotTable Tools OptionsToolsFormulasCalculated Field.
2. In the Name text box, type a name for the formula.
3. In the Formula box, delete the =0 and create your ownformula, following these tips:
Like other Excel formulas, it begins with an equalsign, but you use field names instead of cell references.
You cant use cell references in a formula, butyou can use static values.
Double-click any field name in the Fields box to addit to the formula.
Use the standard formula operators such as plus,minus, multiply, and divide (+, -, *, and /).
4. Click OK. Excel creates a new data column with the calculatedvalue. Calculated field next to the datafield.

Create a PivotChart
1. Create a PivotTable.
2. Click anywhere in the PivotTable. Choose InsertChartsand select a chart type. Excelautomatically creates a
chart from your PivotTable. AllPivotTable data, except for the totals and subtotals,appear in the
PivotChart.Changes to the PivotTable affect the PivotChart, and field changesto the PivotChart affect the
PivotTable.
3. Format the chart with the followingexceptions:
You cannot move or resize the plot area.
You cannot add data to the PivotChart from outsidethe PivotTable.

5 Content by Experts of ADETC


Pivot Charts cannot be Scatter, Bubble, or Stock types.
You can click the Axis Fields drop-down list to filterthe row headings you want to use

Creating new scenarios


When creating a scenario for your worksheet, you create a spreadsheet thatuses certain cells that change in each
scenario (appropriately enough, calledchanging cells). To make it easier to identify the changing cells in each
scenariothat you create (especially in any scenario summary reports that yougenerate), you should assign range
names to the variables in the spreadsheetwith the Name a Range or Create from Selection command buttonson
the Formulas tab of the Ribbon before you create your scenarios.
To create your scenarios with the Scenario Manager, follow these steps:

1. Select the changing cells in the spreadsheet; that is, the cells whose values vary in each of your
scenarios.Remember that you can select nonadjacent cells in the worksheet byholding down the Ctrl key as you
click them.

2. Click the What-If Analysis command button on the Ribbons Datatab and then click Scenario Manager on its
drop-down menu orpress Alt+AWS. This action opens the Scenario Manager dialog box

3. Click the Add button in the Scenario Manager dialog box.


This action opens the Add Scenario dialog box. The Add Scenario dialog box contains a Scenario Name text
box,where you give the new scenario a descriptive name such as Best Case,Most Likely Case, and so on. This
dialog box also contains a Changing Cellstext box that contains the addresses of the variable cells that you
selectedin the worksheet and a Comment box that contains a note with your nameand the current date, so youll
always know when you created the particularscenario.

4. Type a descriptive name for the new scenario in the Scenario Nametext box.
Now, you should check over the cell references in the Changing Cellstext box to make sure that theyre correct.
You can modify them if necessaryby clicking the Changing Cells text box and then by clicking the cells in the
worksheet while holding down the Ctrl key. You can also editthe note in the Comment box if you want to add
more information aboutyour assumptions as part of the new scenario.

6 Content by Experts of ADETC


By default, Excel protects a scenario from changes when you turn onprotection for the worksheet so that
you cant edit or delete the scenario in any way. If you want Excel to hidethe scenario as well when worksheet
protection is turned on, click theHide check box. If you dont want to protect or hide the scenario whenworksheet
protection is turned on, click the Prevent Changes check boxto remove its check mark, and leave the Hide check
box as it is.

5. In the Protection section of the Add Scenario dialog box, choose whatkind of scenario protection that you
need, if any, with the PreventChanges and Hide check boxes.Now youre ready to specify the changing values for
the new scenario.

6. Click OK in the Add Scenario dialog box.


This action closes the Add Scenario dialog box and then opens theScenario Values dialog boxTheScenario Values
dialog box numbers and shows the range name (assumingthat you named each of the cells), followed by the
current value foreach of the changing values that you selected in the worksheet beforestarting to define different
scenarios for your spreadsheet.You can accept the values shown in the text box for each changing cellif it suits the
current scenario that youre defining, or you can increase or decrease any or all of them as needed to reflect the
scenarios assumptions.

7. Check the values in each changing cells text box and modify thevalues as needed.
Now youre ready to close the Scenario Values dialog box, which completesthe definition of the new scenario.

8. Click the Add button in the Scenario Values dialog box.This action closes the Scenario Values dialog box and
returns you to theAdd Scenario dialog box, where you can define a new scenario name for the changing cells.

7 Content by Experts of ADETC


9. Repeat Steps 4 to 7 to add all the other scenarios that you want tocreate.
After you finish defining all the different scenarios you want to apply tothe changing values in the spreadsheet,
you can close the ScenarioValues dialog box and then return to the Scenario Manager dialog boxwhere you can
use the Show button to see how using different sets ofchanging values affects your spreadsheet.

10. Click OK in the Add Values dialog box and then click the Close buttonin the Scenario Manager dialog box.
When you return to the Scenario Manager dialog box, the names of all thescenarios that you added appear in the
Scenarios list box.
To show a particular scenario in the worksheet that uses the values youentered for the changing cells, you simply
double-click the scenario name inthis list box or click the name and then click the Show command button.
If, after creating the scenarios for your worksheet, you find that you need touse different input values or you
want to add or remove scenarios, you canedit the scenarios in the Scenario Manager dialog box. To modify the
scenariosname and/or the input values assigned to the changing cells of thatscenario, click the scenario name in
the Scenarios list box and then click theEdit button so that you can make the appropriate changes in the Edit
Scenariodialog box. To remove a scenario from a worksheet, select the scenariosname in the Scenarios list box
and then click the Delete button.

You can also merge scenarios from other Excel workbook files that are open(of course, the workbooks should
share the same spreadsheet layout andchanging cells). To merge a scenario into the current worksheet from
anotherworkbook, click the Merge button in the Scenario Manager dialog box, and
then select the workbook in the Book drop-down list box and the worksheetin the Sheet drop-down list box
before you click OK. Excel then copies all thescenarios defined for that worksheet and merges them with any
scenariosthat youve defined for the current worksheet.
Producing a summary report
After creating the different scenarios for your worksheet, you can use theSummary button in the Scenario
Manager dialog box to create a summaryreport that shows the changing values used in each scenario and, if you
want,key resulting values that each produces. When you click the Summary button,Excel opens a Scenario
Summary dialog boxwhere you may designate a cell selection of result cells in theResult Cells text box to be
included in the report. After selecting the resultcells for the report, click OK to have Excel generate the summary
report anddisplay it in a new worksheet window.

8 Content by Experts of ADETC


The cell range B7:F7, containing the projectedincome figures for the sales forecast, are designated as the result
cellsto be included in the summary report. Figure 1-10 shows the actual summary report generated for this
sample worksheet in a new document window. Notethat because all the changing and result cells in this
worksheet are named,the summary report uses their range names in place of their cell references.
Also, when the Scenario Manager generates a summary report, it automaticallyoutlines the summary data, thus
creating two vertical levels one forthe changing cells and another for the result cells.

Performing goal seeking

To use the Goal Seek command, simply select the cell containing the formulathat will return the result that you
are seeking (referred to as the set cell),indicate what value you want this formula to return, and then indicate
thelocation of the input value that Excel can change to return the desired result.
To find out how much sales must increase to return a net income of$300,000 in the first quarter, you first select
cell B7, which contains the formulathat calculates the first quarter income before you click Goal Seek onthe What-
If Analysis buttons drop-down menu on the Ribbons Data tab orpress Alt+AWG. This action opens the Goal Seek
dialog box. Because cell B7 is the active cell when you openthis dialog box, the Set Cell text box already contains
the cell reference B7.You then select the To Value text box and enter 300000 as the goal. Then,you select the By
Changing Cell text box and select cell B3 in the worksheet(the cell that contains the first quarter sales).The Goal
Seek Status dialog box that appears whenyou click OK in the Goal Seek dialog box to have Excel go ahead and
adjustthe sales figure to reach your desired income figure. As this figure shows,Excel increases the sales in cell B3
from $250,000 to $352,941.18, which, inturn, returns $300,000 as the income in cell B7. The Goal Seek Status
dialogbox informs you that goal seeking has found a solution and that the currentvalue and target value are now
the same (if this were not the case, the Stepand Pause buttons in the dialog box would become active, and you
couldhave Excel perform further iterations to try to narrow and ultimately eliminate the gap between the target
and current values).

9 Content by Experts of ADETC


If you want to keep the values entered in the worksheet as a result of goalseeking, click OK to close the Goal Seek
Status dialog box. If you want toreturn to the original values, click the Cancel button instead. If you changethe
value by clicking OK, remember that you can still switch between thebefore and after input values and results
by click the Undo button onthe Quick Access toolbar or by pressing Ctrl+Z.

About Data Validation


Excels data validation feature enables you to set up certain rules that dictate what can be entered into a cell. For
example, you may want to limit data entry in a particular cell to whole numbers between 1 and 12. If the user
makes aninvalid entry, you can display a custom message.
Excel makes it easy to specify the validation criteria, and you can also use a formula for more complex criteria
Specifying Validation Criteria
To specify the type of data allowable in a cell or range, follow these steps:
1. Select the cell or range.
2. Choose Data Data Tools Data Validation. Excel displays its Data Validation dialog box.
3. Click the Settings tab

10 Content by Experts of ADETC


FIGURE 25.2
The Settings tab of the Data Validation dialog box.
4. Choose an option from the drop-down box labeled Allow. The contents of the Data Validation dialog box will
change, displaying controls based on your choice. To specify a formula, select Custom.

5. Specify the conditions by using the displayed controls. Your selection in Step 4 determines what other controls
you can access.

6. (Optional) Click the Input Message tab and specify which message to display when a user selects the cell. You
can use this optional step to tell the user what type of data is expected. If this step is omitted, no message will
appear when the user selects the cell.

7. (Optional.) Click the Error Alert tab and specify which error message to display when a
user makes an invalid entry. The selection for Style determines what choices users have when they make invalid
entries. To prevent an invalid entry, choose Stop. If this step is omitted, a standard message will appear if the user
makes an invalid entry.

8. Click OK.
After youve performed these steps, the cell or range contains the validation criteria you specified.

Types of Validation Criteria You Can Apply


The Settings tab of the Data Validation dialog box enables you to specify a wide variety of data validation criteria.
The following options are available in the Allow drop-down box. Keep in mind that the other controlsin the
Settings tab vary, depending on your choice in the Allow drop-down box.
Any Value: Selecting this option removes any existing data validation. Note, however, that the input message, if
any, still displays if the check box is checked in the Input Message tab.
Whole Number: The user must enter a whole number. You specify a valid range of whole numbers by using the
Data drop-down list. For example, you can specify that the entry must be a whole number greater than or equal
to 100.

11 Content by Experts of ADETC


Decimal: The user must enter a number. You specify a valid range of numbers by using the Data drop-down list.
For example, you can specify that the entry must be greater than or equal to 0 and less than or equal to 1.

List: The user must choose from a list of entries you provide.

Date: The user must enter a date. You specify a valid date range by using the Data drop-down list. For example,
you can specify that the entered data must be greater than or equal to January 1, 2007, and less than or equal to
December 31, 2007.

Time: The user must enter a time. You specify a valid time range by using the Data drop-down list. For example,
you can specify that the entered data must be greater than 12:00 p.m.

Text Length: The length of the data (number of characters) is limited. You specify a valid length by using the Data
drop-down list. For example, you can specify that the length of the entered data be 1 (a single alphanumeric
character).

Custom: To use this option, you must supply a logical formula that determines the validity of the users entry (a
logical formula returns either True or False). You can enter the formula directly into the Formula control (which
appears when you select the Custom option), or you can specify a cell reference that contains a formula. This
chapter contains examples of useful formulas.

The Settings tab of the Data Validation dialog box contains two other check boxes:

Ignore Blank: If checked, blank entries are allowed.

Apply These Changes to All Other Cells with the Same Setting: If checked, the changes youmake apply to all
other cells that contain the original data validation criteria.
Its important to understand that, even with data validation in effect, the user can enter invalid data. If the
Style setting in the Error Alert tab of the Data Validation dialog box is set to anything except Stop, invaliddata can
be entered. Also, remember that data validation does not apply to the calculated results of formulas.

In other words, if the cell contains a formula, applying conditional formatting to that cell will have no effect. Excel
can draw circles around invalid entries (in this case, cells that contains values greater than 100).

Creating a Drop-Down List


Perhaps one of the most common uses of data validation is to create a drop-down list in a cell.

12 Content by Experts of ADETC


To create a drop-down list in a cell:

1. Enter the list items into a single-row or single-column range. These items are the ones that appear in the
drop-down list.

2. Select the cell that will contain the drop-down list and access the Data Validation dialog box.

3. In the Settings tab, select the List option and specify the range that contains the list using the Source control.

4. Make sure that the In-Cell Dropdown check box is checked.

5. Set any other Data Validation options as desired.


After performing these steps, the cell displays a drop-down arrow when its activated. Click the arrow and choose
an item from the list that appears.

Data Validation Examples


Accepting text only
Excel has a Data Validation option to limit the length of text entered into a cell, but it doesnt have an option to
force text (rather than a number) into a cell. To force a cell or range to accept only text (no values), use the
following data validation formula:
=ISTEXT(A1)
This formula assumes that the active cell in the selected range is cell A1.
Accepting a larger value than the previous cell
The following data validation formula enables the user to enter a value only if its greater than the value inthe cell
directly above it:
=A2>A1
This formula assumes that A2 is the active cell in the selected range. Note that you cant use this formula fora cell
in row 1.
Accepting non duplicate entries only
The following data validation formula does not permit the user to make a duplicate entry in the range
A1:C20:

13 Content by Experts of ADETC


=COUNTIF ($A$1:$C$20,A1)=1
This formula assumes that A1 is the active cell in the selected range. Note that the first argument for COUNTIF is
an absolute reference. The second argument is a relative reference, and it adjusts for each cell in the validation
range. Figure 25.6 shows this validation criterion in effect, using a custom error alert message. The user is
attempting to enter 17 into cell B6.

Using data validation to prevent duplicate entries in a range.

Accepting text that begins with A


The following Data Validation formula demonstrates how to check for a specific character. In this case, the
formula ensures that the users entry is a text string that begins with the letter A (either uppercase or lowercase).
=LEFT(A1)=a
This formula assumes that the active cell in the selected range is cell A1.
The following formula is a variation of this validation formula. In this case, the formula ensures that the entry
begins with the letter A and contains exactly five characters.
=COUNTIF(A1,A????)=1
Accepting only a date thats a Monday
The following Data Validation formula ensures that the cell entry is a date, and the date is a Monday.
=WEEKDAY(A1)=2
This formula assumes that the active cell in the selected range is cell A1. It uses the WEEKDAY function, which
returns 1 for Sunday, 2 for Monday, and so on.
Accepting only values that dont exceed a total
The following Data Validation formula ensures that the sum of the budget items does not exceed the budget:
=SUM($B$1:$B$6)<=$E$5

Building SimpleMacros
You can often save yourself time by automating tasks you perform frequently. The automation takes the form of
an Excel Macro, which is a series of commands and functions grouped together as a single command. Macros are
created in a special programming language called Visual Basic and can be run whenever you need to perform the
task. Although you can write your own very complex macros in the Visual Basic programming language, the
easiest method for creating many macros is to use the Excel Macro Recorder. When you record a macro, Excel
stores information about each step you take as you perform a series of commands. You then run the macro to

14 Content by Experts of ADETC


repeat, or play back, the commands. The macro recorder is very literal and records every action you complete.
Therefore, planning your macro before you begin the recording process is very important so you dont record
unnecessary steps. Security is an important issue when working with macros. If you open worksheets containing
macros from outside sources, these macros can be harmful to your computer. By default, Excel protects you from
running macros, but if youre creating your own macros, youll probably change these protective security settings.

Display the Developer Tab


1. Choose Office Button Excel Options. The Excel Options dialog box appears.
2. From the Popular section, check the option Show Developer Tab in the Ribbon.
3. Click OK. The Developer tab appears, with Macro options.

Record a Macro
1. Choose Developer Code Record Macro.
2. Type a name and optional description for the macro.
3. From the Store Macro In drop-down list, select where you want to store the macro:
This Workbook: Save the macro in only the current workbook file.
New Workbook: Create macros that you can run in any new workbooks created during the current Excel
session.
Personal Macro Workbook: Choose this option if you want the macro to be available whenever you use
Excel, regardless of which worksheet you are using.
4. Click OK. The Record Macro option changes to Stop Recording.
5. Perform the actions you want to record. Excel is recording your keystrokes as you type.
6. Choose Developer Code Stop Recording.

Assign a Macro Keystroke


1. Choose Developer Code Record Macro.
2. In the Macro Name text box, type a name for the macro.3. From the Store Macro drop-down list, select where
you want to store the macro.
4. Optionally, in the description box, type a description of the macro.
5. Assign a keystroke combination .If you select a shortcut key already used in Excel, the macro shortcut key
overrides the Excel shortcut key while the workbook that contains the macro is open. If you enter a lowercase
letter, Excel assigns it a CTRL+ lowercase letter combination. If you type an uppercase letter, you must press
CTRL+SHIFT+ the letter to run the macro. The shortcut key cannot be a number or special character.
6. Click OK.
7. Perform the actions you want to record.
8. Click the Stop Recording button on the Stop Recording toolbar, or choose Tools Macro Stop Recording.
9. To execute the macro, press the shortcut key you assigned or choose the macro from Tools Macro Macros.

Run a Macro
1. Choose Developer Code Macros.
2. Select the macro you want to run.
3. Click Run. Excel executes the selected macro.

Save a Macro-Enabled Workbook


1. Choose Office Button Save As. The Save As dialog box appears.
2. Enter a name and select a location for your workbook.
3. Click the Save as Type drop-down arrow. A list of file types appears.

15 Content by Experts of ADETC


4. Choose Excel Macro-Enabled Workbook. Excel adds the .xlsm extension to the filename.
If you neglect to save the workbook as a Macro-enabled workbook ,you see the warning message telling youthat
the macro will not be retained.

Open a Macro-Enabled Workbook


1. Open a workbook containing a macro. The workbookopens as usual but a Security Warning message
appearsbelow the ribbon.
2. Click Options. The Microsoft Office Security Optionsdialog box appears.
3. Click Enable This Content only if you know where themacro originated.
4. Click OK. The dialog box closes, along with the SecurityWarning message.

Check Macro Security Level


1. Choose DeveloperCodeMacro Security. The TrustCenter dialog box appears.
2. Set a security level:
Disable all macros without notification: Allows youto run only macros that are stored in a trusted location.
Click the Trusted Location section to managethese trusted locations.
Disable all macros with notification: Displays asecurity alert when a workbook with macros opens.
You can then decide whether to enable the macrosassociated with the workbook. This is the Excel default setting.
Disable all macros except digitally signed macros:
You can only run only those macros that are digitallysigned.
A digital signature is an electronic, encrypted, secure stamp ofauthentication obtained from a commercial
certification authority.Excels Visual Basic programming language contains a self-certifying
digital signature tool, but because it doesnt come from a thirdparty, Excel still considers it unauthenticated and
displays a warningbox before running self-certified macros.
Enable all macros: Allows macros to run without anotification. This can be helpful if you run a lot of macros, but
be aware of the risk when using macros from unknown sources.
3. Click OK.

Add a Macro Button to theQuick Access Toolbar


1. Choose Office ButtonExcel Options.
2. Click the Customize section
3. From the Choose command from drop-down list, selectMacros.
4. Select the macro you want displayed on the QuickAccess toolbar.
5. Click Add. An icon is added to the right panel.
6. Click the newly added macro command.
7. Click Modify. You see the Modify Button dialog box,
8. Choose an icon to represent the macro.
9. Click OK.
10. Click OK to close the Excel options dialog box. Excel nowdisplays a macro button in the Quick Access toolbar.
11. To run the macro, click the toolbar button.

Delete a Macro
1. Open the workbook containing the macro you want todelete.
2. Choose DeveloperCodeMacros.
3. From the Macro dialog box, select the name of themacro you want to delete.
4. Click Delete. A confirmation box appears.
5. Click Yes.

16 Content by Experts of ADETC