Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Excel_2010_Bible.pdf
Скачиваний:
26
Добавлен:
13.03.2015
Размер:
11.18 Mб
Скачать

CHAPTER

Using Data

Validation

This chapter explores a very useful Excel feature: data validation. Data validation enables you to add dynamic elements to your worksheet without using any macro programming.

About Data Validation

The Excel data validation feature allows 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 an invalid entry, you can display a custom message, such as the one shown in Figure 25.1.

FIGURE 25.1

Displaying a message when the user makes an invalid entry.

IN THIS CHAPTER

An overview of Excel’s data validation feature

Practical examples of using data validation formulas

569

Part IV: Using Advanced Excel Features

Excel makes it easy to specify the validation criteria, and you can also use a formula for more complex criteria.

Caution

The Excel data validation feature suffers from a potentially serious problem: If the user copies a cell that does not use data validation and pastes it to a cell that does use data validation, the data validation rules are deleted. In other words, the cell then accepts any type of data. n

Specifying Validation Criteria

To specify the type of data allowable in a cell or range, follow the steps below while you refer to Figure 25.2, which shows all three tabs of the Data Validation dialog box.

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.

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

FIGURE 25.2

The three tabs of the Data Validation dialog box.

570

Chapter 25: Using Data Validation

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. The cell or range contains the validation criteria you specified.

Caution

Even with data validation in effect, a user can enter invalid data. If the Style setting on the Error Alert tab of the Data Validation dialog box is set to anything except Stop, invalid data 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. n

Types of Validation Criteria You Can Apply

From the Settings tab of the Data Validation dialog box, you can specify a wide variety of data validation criteria. The following options are available from the Allow drop-down list. Keep in mind that the other controls on the Settings tab vary, depending on your choice from the Allow dropdown list.

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 on 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.

Decimal: The user must enter a number. You specify a valid range of numbers by refining the criteria from choices in 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. This option is very useful, and I discuss it in detail later in this chapter. (See “Creating a drop-down list.”).

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

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

571

Part IV: Using Advanced Excel Features

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 user’s 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 selected, blank entries are allowed.

Apply These Changes to All Other Cells with the Same Setting: If selected, the changes you make apply to all other cells that contain the original data validation criteria.

Tip

The Data Data Tools Data Validation drop-down list contains an item named Circle Invalid Data. When you select this item, circles appear around cells that contain incorrect entries. If you correct an invalid entry, the circle disappears. To get rid of the circles, choose Data Data Tools Data Validation Clear Validation Circles. In Figure 25.3, invalid entries are defined as values that are greater than 100. n

FIGURE 25.3

Excel can draw circles around invalid entries (in this case, cells that contain values greater than 100).

572

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]