Question: I'm looking for tips which can help me in creating a data column (Alphanumeric) in Excel where each row has to hold unique data. If a user enters a duplicate value in the column, the spreadsheet should not accept this value. Answer: There are several "events" available within an Excel spreadsheet where you can place VBA code. In your case, we want to check for a duplicate value when the "Worksheet_Change" event fires. Let's take a look at an example. Download Excel spreadsheet (as demonstrated below)
|
In our spreadsheet, we've set up column A in Sheet1 to contain unique values. On this sheet, we've placed code on the "Worksheet_Change" event, so that whenever a value is entered in column A (within the first 200 rows), the macro will test to see if this value has been entered before. If the value is a duplicate, the following message will appear:
|
And the background color of the cell that contains the duplication will turn red.
|
In this example, we've entered the value 1234 in cell A5 which already exists in cell A2. You can press Alt-F11 to view the VBA code. Macro Code:The macro code looks like this:
|
Visit our busy book shop, were you can find latest books for beginners as well as advanced excel users.
Spreadsheet 123 Spreadsheet Software Development
See Spreadsheets for:
a.Hotel Management b.Personal Budget
c.Corporate Finance d.Rating Calculation e.Real Estate and Mortgage
f.Web Calc