Beruflich Dokumente
Kultur Dokumente
ablebits.com /office-addins-blog/2017/08/16/data-validation-excel/
Here are just a few examples of what Excel's data validation can do:
For instance, you can set up a rule that limits data entry to 4-digit numbers between 1000 and 9999. If the user
types something different, Excel will show an error alert explaining what they have done wrong:
1/15
On the Settings tab, define the validation criteria according to your needs. In the criteria, you can supply any of
the following:
Values - type numbers in the criteria boxes like shown in the screenshot below.
Cell references - make a rule based on a value or formula in another cell.
Formulas - allow to express more complex conditions like in this example.
As an example, let's make a rule that restricts users to entering a whole number between 1000 and 9999:
With the validation rule configured, either click OK to close the Data Validation window or switch to another tab to
add an input message or/and error alert.
If you want to display a message that explains to the user what data is allowed in a given cell, open the Input
Message tab and do the following:
Make sure the Show input message when cell is selected box is checked.
Enter the title and text of your message into the corresponding fields.
Click OK to close the dialog window.
2/15
As soon as the user selects the validated cell, the following message will show up:
Stop
(default)
Warning
3/15
Information
To configure a custom error message, go to the Error Alert tab and define the following parameters:
Check the Show error alert after invalid data is entered box (usually selected by default).
In the Style box, select the desired alert type.
Enter the title and text of the error message into the corresponding boxes.
Click OK.
And now, if the user enters invalid data, Excel will display a special alert explaining the error (like shown in the
beginning of this tutorial).
Note. If you do not type your own message, the default Stop alert with the following text will show up: This value
does not match the data validation restrictions defined for this cell.
As you already know, the validation criteria are defined on the Settings tab of the Data Validation dialog box
(Data tab > Data Validation).
4/15
Whole numbers and decimals
To restrict data entry to a whole number or decimal, select the corresponding item in the Allow box. And then,
choose one of the following criteria in the Data box:
For example, this is how you create an Excel validation rule that allows any whole number greater than 0:
To validate dates, select Date in the Allow box, and then pick an appropriate criteria in the Data box. There are
quite a lot of predefined options to choose from: allow only dates between two dates, equal to, greater than or
less than a specific date, and more.
Similarly, to validate times, select Time in the Allow box, and then define the required criteria.
For example, to allow only dates between Start date in B1 and End date in B2, apply this Excel date validation
rule:
5/15
To validate entries based on today's data and current time, make your own data validation formulas as shown in
these examples:
Text length
To allow data entry of a specific length, select Text length in the Allow box, and choose the validation criteria in
accordance with your business logic.
Note. The Text length option limits the number of characters but not the data type, meaning the above rule will
allow both text and numbers under 10 characters or 10 digits, respectively.
6/15
Excel data validation list (drop-down)
To add a drop-down list of items to a cell or a group of cells, select the target cells and do the following:
1. Open the Data Validation dialog box (Data tab > Data Validation).
2. On the Settings tab, select List in the Allow
3. In the Source box, type the items of your Excel validation list, separated by commas. For example, to limit
the user input to three choices, type Yes, No, N/A.
4. Make sure the In-cell dropdown box is selected in order for the drop-down arrow to appear next to the
cell.
5. Click OK.
The resulting Excel data validation list will look similar to this:
Supplying comma-separated lists directly in the Source box is the fastest way that works well for small
dropdowns that are unlikely to ever change. In other scenarios, you can proceed with one of the following ways:
In addition to built-in Excel data validation rules discussed in this tutorial, you can create custom rules with your
own data validation formulas. Here are just a few examples:
For more examples, please see Custom data validation rules and formulas.
7/15
How to edit data validation in Excel
To change an Excel validation rule, perform these steps:
For instance, you can edit your Excel data validation list by adding or removing items from the Source box, and
have these changes applied to all other cells containing the same drop-down list:
1. Select the cell to which the validation rule applies and press Ctrl + C to copy it.
2. Select other cells you want to validate. To select non-adjacent cells, press and hold the Ctrl key while
selecting the cells.
3. Right-click the selection, click Paste Special, and select Validation from the context menu. Alternatively,
press the Paste Special > Validation shortcut: Ctrl + Alt + V, then N.
4. Click OK.
8/15
Tip. Instead of copying data validation to other cells, you can convert your dataset to an Excel table. As you add
more rows to the table, Excel will apply your validation rule to new rows automatically.
This will select all cells that have any data validation rules
applied to them:
9/15
How to remove data validation in Excel
Overall, there are two ways to remove validation in Excel: the standard approach designed by Microsoft and the
mouse-free technique devised by Excel geeks who would never take their hands off the keyboard
unless absolutely necessary (e.g. to take a cup of coffee :)
Normally, to remove data validation in Excel worksheets, you proceed with these steps:
Tips:
1. To remove data validation from all cells on the current sheet, use the Find & Select feature to select all of
the validated cells.
2. To remove a certain data validation rule, select any cell with that rule, open the Data Validation dialog
window, check the Apply these changes to all other cells with the same settings box, and then click the
Clear All button.
As you see, the standard method is pretty fast but does require a few mouse clicks, no big deal as far as I'm
concerned. But if you prefer working with the keyboard over a mouse, you may find the following approach
appealing.
De jure, Excel Paste Special is designed for pasting specific elements of copied cells. De facto, it can do many
more useful things. Among others, it can quickly remove data validation rules in a worksheet. Here's how:
1. Select an empty cell without data validation, and press Ctrl + C to copy it.
2. Select the cells(s) from which you want to remove data validation.
3. Press Ctrl + Alt + V, then N, which is the shortcut for Paste Special > Data Validation.
4. Press Enter. Done!
10/15
Excel data validation tips
Now that you know the basics of data validation in Excel, let me share a few tips that can make your rules a
whole lot more effective.
Instead of typing values directly in the criteria boxes, you can enter them in some cells, and then refer to those
cells. If you decide to change the validation conditions later, you will simply type new numbers on the sheet,
without having to edit the rule.
To enter a cell reference, either type it in the box preceded by an equal sign, or click the arrow next to the box,
and then select the cell using the mouse. You can also click anywhere within the box, and then select the cell on
the sheet.
For example, to allow any whole number other than the number in A1, pick the not equal to criteria in the Data
box and type =$A$1 in the Value box:
To take a step further, you can enter a formula in the referenced cell, and have Excel validate the input based on
that formula.
For example, to restrict users to entering dates after today's date, enter the =TODAY() formula in some cell, say
B1, and then set up a Date validation rule based on that cell:
11/15
Or, you can enter the =TODAY() formula directly in the Start date box, which will have the same effect.
In situations when it's not possible to define a desired validation criteria based on a value or cell reference, you
can express it using a formula.
For example, to limit the entry to the minimum and maximum values in the existing list of numbers, say A1:A10,
use the following formulas:
=MIN($A$1:$A$10)
=MAX($A$1:$A$10)
Please pay attention that we lock the range by using the $ sign ( absolute cell references) so that our Excel
validation rule works correctly for all selected cells.
12/15
How to find invalid data on the sheet
Although Microsoft Excel allows applying data validation to cells that already have data in them, it won't notify
you if some of the existing values do not meet the validation criteria.
To find invalid data that had made its way into your worksheets before you added data validation, go to the Data
tab, and click Data Validation > Circle Invalid Data.
This will highlight all cells that don't meet the validation criteria:
As soon as you correct an invalid entry, the circle will be gone automatically.
To remove all circles, go to the Data tab, and click Data Validation > Clear
Validation Circles.
Data validation in Excel is designed to prohibit typing invalid data directly in a cell, but it cannot stop users from
copying invalid data. Though there is no way to disable copy/paste shortcuts (other than by using VBA), you can
at least prevent copying data by dragging and dropping cells. To do this, go to File > Options > Advanced
> Editing options, and clear the Enable fill handle and cell drag-and-drop check box.
13/15
Excel data validation is unavailable when in cell edit mode
The Data Validation command is unavailable (greyed out) if you are entering or changing data in a cell. After
you've finished editing the cell, press Enter or Esc to quit the edit mode, and then do data validation.
Although the existing validation rules keep working in protected and shared workbooks, it's not possible to
change data validation settings or set up new rules. To do this, unshare and/or unprotect your workbook first.
When doing formula-based data validation in Excel, there are three important things to check:
For more information, please see Custom data validation rule not working.
If the Manual Calculation mode is turned on in your Excel, uncalculated formulas can prevent data from being
validated correctly. To change the Excel calculation option back to automatic, go to the Formulas tab >
Calculation group, click the Calculation Options button, and then click Automatic.
For more information, please see Automatic calculation vs. Manual calculation.
That's how you add and use data validation in Excel. I thank you for reading and hope to see you on our blog next
week!