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 next cell to be entered is A9. Click in cell A9, and select Data>Validation from the menu.
- In the "Allow:" drop down box, choose "Custom"
- Enter this formula exactly how it appears: =ISNA(VLOOKUP(A9,A$1:A8,1,FALSE))
- Click the Error Alert tab in the Data Validation dialog box.
- Make sure that the "Show alert" box is checked.
- For Style:, pick Stop
- Enter a Title of "Non Unique Value"
- Enter a message of "You must enter a unique invoice number."
- Click "OK"
The final thing to do is to copy this validation from cell A9 to the other cells in column A.
- Click in column A and select Edit>copy to copy the cell.
- Select a large range of cells in column A. Perhaps A10:A500.
- Select Edit, Paste Special. From the Paste Special dialog, select "Validation" and click OK. The validation rule that you entered from cell A9 will be copied into all of the cells down to A500.
That is all that you need to know to make it work. For those of you who want to know more, I will explain in English how the formula is working.
=ISNA(VLOOKUP(A9,A$1:A8,1,FALSE))
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.
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.