Excel – Data Validation Error Checking & Other Useful Tips
In my blog “Using Data Validation to Control Data Entry”, we looked at how to set up DATA VALIDATION rules, add prompts and customise alert messages.
Now, let’s look at a few other features you might want to use when working with VALIDATION rules;
- Finding cells that have DATA VALIDATION rules applied
- Checking for data that no longer meets your rules
- Preventing duplicate entries
Finding cells that have DATA VALIDATION rules applied
So, how do you find cells in a worksheet that have validation rules applied to them? You could click in each cell, one at a time and see if a drop down arrow appears. That’s fine as long as the validation involves a drop down list. But what if it has another type of rule or even a custom formula? No hints there!
For this, we need Go To Special. You can find this on the HOME tab under FIND & SELECT.
Click on DATA VALIDATION and any cells that have rules of any sort applied to them will be highlighted.
The grey cells are those with rules applied (the labels in this example also happen to be grey – but it should be pretty obvious when you run this)
If you like your keyboard shortcuts, you can access this by the following combination:
Ctrl + G followed by Alt + S, followed by V and then press ENTER.
Checking for data that no longer meets your rules
As you create your rules, naturally you will test them and make sure they work. But sometimes you may make changes to rules after data has been entered. Unfortunately, Excel will not automatically highlight data that no longer meets your new rules. If you want to check how your data is affected by a new rule and whether it breaks it you need to run CIRCLE INVALID DATA.
If you love your keyboard shortcuts, then you’ll need:
Alt followed by A, followed by V, followed by I.
So make a change to your rule(s) first. Continuing our timesheet example, I set up a rule that limited the comments to 150 characters. I’ve now decided that even that is too much and want to limit it to only 100 characters. I make the necessary change to my rule, but there is already some data in my worksheet. In this example there is a comment that is 126 characters long. This was fine under the old rule but breaks my new one.
Now turn on your CIRCLE INVALID DATA.
When you turn this on, any cells that contain data that breaks the edited rule will be highlighted by a red circle.
Unfortunately, Excel does not do this automatically for you, so you need to remember to do this after you have edited an existing rule. If applicable, make changes to the data in the cell(s) that are circled. Once they meet the new criteria, the circle will disappear.
Preventing duplicate entries
As well as controlling data entry through a set of simple rules you can use formulas to create complex rules with multiple conditions. One example where a formula can come in handy is preventing duplicate entries.
For this we need to use the CUSTOM option when creating our new rule within DATA VALIDATION.
In the FORMULA box enter the following formula:
What this does is check the selected range, in this example A1 to A50. Note the use of absolute references as you have to fix the range that is being checked.
NOTE: if you are applying the rule to an existing list make sure you apply the validation rule BEYOND the end of the list otherwise as you add new records no rule will have been applied to the blank cells and therefore allowing you to potentially add duplicate values.
The next bit A1 says look in cell A1 and check it against every cell in the selected range and count how many times it appears. This is left as a relative reference so that each cell is checked in turn when the formula is copied down the column.
The rule then states that when counted, each cell value must add up to 1 or less which means that if you add a duplicate value the count will be greater than 1 and therefore block it.
Let’s take this one step further…..
What if I want exceptions to the rule?
For that, all I need to do is modify my formula slightly….
Essentially it is the same rule as before but with the addition of an exception. In this example I am allowing the name “Dave” to appear more than once. Note the use of brackets around the first part of the formula.
You can add further exceptions by adding more +(A1=”text”) on the end of the formula.
And there you have a few useful additional features from data validation!