
How can I make sure that duplicate invoice numbers are not entered?.
In Excel 97, you can use the new Data Validation feature to do this. In our example, the invoice numbers are being entered in column A. Here is how to set it up for a single cell:


The final thing to do is to copy this validation from cell A9 to the other cells in column A.
The second bit of trickery is in the second argument for the Vlookup function. I was careful to specify A$1:A8. The dollar sign before the 1 tells Excel that when we copy this validation to other cells, it should always start looking in cell of the current column. This is called an absolute address. I was equally careful not to put a dollar sign before the 8 in A8. This is called a relative address and tells Excel that when we copy this address, it should stop looking in the cell just above the current cell. Then, when we copy the validation and look at the validation for cell A12, the second argument in the vlookup correctly shows A$1:A11.
There are two problems with this solution. First, it will not work in Excel 95. Second, the validations are only performed on cells that change. If you enter a unique value in cell A9, and then go back up and edit cell A6 to be the same value you entered in A9, the validation logic in A9 will not be invoked and you will end up with duplicate values in your worksheet.
The old-fashioned method used in Excel 95 will address both of these issues. In the old method, you would have the validation logic sitting in a temporary column B. To set this up, enter the following formula in cell B9: =ISNA(VLOOKUP(A9,A$1:A8,1,FALSE))
Copy this formula from B9. Paste it in cells B2:B500. Now, as you enter invoice numbers in column A, column B will show TRUE if the invoice is unique, and FALSE if it is not unique.
MrExcel.com provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures on this web site are provided "as is" and we do not guarantee that they can be used in all situations.
Return to the Mr Excel Home Page.
Thanks for visiting Mr Excel.com! Proudly serving the web since November 21, 1998. You are visitor # .
Originally published January 10, 1999. All contents copyright 2008 by MrExcel.com.
Send questions to ask@MrExcel.com
Excel is a registered trademark of the Microsoft Corporation.