It’s often difficult to police a user’s actions within an Excel spreadsheet unless you’re aware of Data Validation. This feature is tucked away on Excel’s Data menu and allows you to create a variety of input rules. This article will demonstrate how to use Excel’s COUNTIF function to trigger an error prompt if a user attempts to enter the same value in a specific area of a spreadsheet.
As shown in the figure below:
- Select the range of cells that you wish to prevent duplicates within.
- Choose Data Validation from the Data menu.
- Choose Custom from the Allow list within the Data Validation dialog box.
- Enter the following formula:
=COUNTIF($A$2:$A$40,A2)=1
Change $A$2:$A$40 to match your desired range of cells. Make sure to include the dollar signs around the range of cells, while A2 should be the address of the first cell in the range, but without dollar signs.
- Activate the Input Message tab of the Data Validation dialog box.
- Provide a title for the prompt that you wish to appear when the user clicks on a cell that you’re restricting.
- Provide an input message to document the restriction.
- Activate the Error Alert tab of the Data Validation dialog box.
- Provide a title for the error prompt that should appear if the user enters a duplicate value.
- Provide an error message that should appear if the user enters a duplicate value.
- Click OK to close the Data Validation dialog box.
- Test your work by entering a duplicate value.
To remove Data Validation, click on any cell that has a restriction in place, and then choose Data Validation from the Data menu. Click the Apply These Changes To All Other Cells With the Same Settings checkbox, and then click the Clear All button.
