Search This Blog

Thursday 25 March 2010

Force unique numbers

Start by clicking in cell A1 and selecting Data | Validation from the menu. Click the drop-down list that is titled Allow and select Custom from the list. A box titled Formula will appear; enter this formula: =COUNTIF(A:A,A1)=1. Now click the Error Alert tab and enter an appropriate title and error message. For example, you could set the title to "Unique Values Only" and the message to "You must enter a value that is not already present in this column." Then click OK to accept the validation rule.

Now click the heading for column A to select the entire column. Again select Data | Validation from the menu. Excel will ask if you want to extend data validation to the additional cells. Click Yes, click OK, and you're done. If you accidentally attempt to enter a nonunique value in column A, Excel will block it and display the error message you defined.