Let us learn a nice trick today, which can help you to stop duplicates from entering your file.
There are definitely good tools to easily track and report
duplicates, like the “Highlight duplicates” feature of the Conditional
Formatting group, but we are going to learn a preventive mechanism whereby the duplicate
is arrested on entry itself and not as a post mortem exercise.
We shall use the technique of Data Validation to get this
done. Given below is a sample scenario and solution:
- Select the range in which you want to prevent duplicates – this could be say the range of cells from G1 to G80.
- From the Ribbon, click on Data->Data Validation (alternate is to use the shortcut keys Alt+D, followed by L)
- In the first tab of the dialog (Settings), select “Custom” from the “Allow” dropdown box.
- Now you will get a box to enter formula.
- In the formula box type this: =COUNTIF($G$1:$G$80,G1)=1
- Your sentry tool is now ready for operation, but we will give it some dialogue to display.
- You have an option to present a customized error message to the users who enter a duplicate value. To configure this, select the Error Alert tab of the dialog box.
- In the Title box type "Stop Duplicates!" (or any such thing you like – may be add in your name too to make it very customized)
- In the Error Message box type "You are trying to enter a duplicate value. Please enter non-duplicates only. " (or any such thing you like)
- We are all set , just click on the OK button to set the validation on.
The formula used:
If you see the formula used in Step 5 above, it is a simple
COUNTIF formula which tells Excel to count how many times the data from the
current cell (G1) is included in the range G1:G80.
Excel automatically changes the current cell reference – so if
you go to Cell G23 and open the data validation rule again, you will see that
the formula would have changed to G23 – like this: =COUNTIF($G$1:$G$80,G23)=1
The formula evaluates and if the count of such values is
equal to 1, it means there is no duplicate value. The condition evaluates to
TRUE and everything passes through OK. However, if there is a duplicate being
entered, the formula evaluates to FALSE (answer not equal to 1), and triggers
the error alert, which you have customized above.
Now you have the right tools with you, so just go ahead and
stop the dupes ;)
Note: Some of the tips shown here are extracts from my book on "Excel for the CEO" - details available atwww.mrexcel.com/ceo.shtml. You can also find this in the ebook edition "Excel for the Small Business Owner" available for online ordering at www.mrexcel.com/sbo.shtml
Note: Some of the tips shown here are extracts from my book on "Excel for the CEO" - details available atwww.mrexcel.com/ceo.shtml. You can also find this in the ebook edition "Excel for the Small Business Owner" available for online ordering at www.mrexcel.com/sbo.shtml
No comments:
Post a Comment