- Select the range of cells in which you want to prevent duplicates (for example, B2:B1048576).
- From the Data menu select Validation.
- Click on the Settings tab.
- From the Allow dropdown box select Custom.
- In the formula box type =COUNTIF($B$2:$B$1048576,B2)=1 (see explanation below)
- Click on the Error Alert tab.
- In the Title box type "Duplicate Entry!"
- In the Error Message box type "You cannot enter a value already in the list."
This formula tells Excel to count how many times the data from the current cell is included in the validation range. If the answer is equal to 1 then the formula =COUNTIF($B$2:$B$1048576,B2)=1 is TRUE and everything is OK. However, if the answer is not equal to 1, then the formula is FALSE and an error occurs causing the Error Alert.