- 2007 Office System Sample: Visual Studio Code Snippets for the Office Fluent UI
- C# Code Snippets
- ASP.NET 2.0 CSS Friendly Control Adapters 1.0
- ASP.NET Ajax Extentions
- VS 2005 Web Application Projects
- VS 2005 Web Deployment Projects
- Nikhil's Web Development Helper
- IE Development Toolbar
- DocProject
- EAP
- Disable Script Debugging thru VS 2008
Thursday, May 15, 2008
Required Add-ons for VS 2005 or IE
Friday, June 30, 2006
Avoiding Duplicate Key Values in Excel
A co-worker was looking to store some records in Excel, but wanted to make sure that there were no duplicate values within the key field. Since this was just a flat record system, converting it to Access of FileMaker Pro seemed like overkill, but we were at a loss as to how to prevent key values in Excel since it is not a database system and does not index. The short answer is, you can't without VBA. However, with a little formula you can help avoid the problem of duplicate entries. This is actually a two step process, though for simplicities sake you only need do the first one.
Conditional Formatting
To avoid duplicates, you can emply conditional formatting. This will enable any duplicate values to show up as a different colour and give you a visual clue that this was a duplicate. The draw back to this step, is it does not prevent duplicates it only warns you that you have made a duplicate but it is still up to you to change the key value so it is no longer a duplicate. Here is how to set up the conditonal formatting:- Go to the cell that will contain the key entry for your first record. (In this example we use row 1 for a header, and column A is where we are typing our key values. So, our first record will go on row 2, since 1 is for headers, making the cell we select A2)
- Click on the Format menu, then click on Conditional Formatting... ( a pop-up box will display)
- There should be a drop-down box that says "Cell Value Is". Click the down-arrow next to that and change the selection to "Formula Is"
- To the right of our drop-down box is where we will type our formula. This is the formula you will want to type out:=COUNTIF(A:A,A2)>1
- Now that we have told Excel what to look for, we need to tell it how to format the cells. Click on the Format... button in the dialogue box, another pop-up box will display.
- Choose your format to anything you want, I chose changing the font to white and then clicked on the Patterns tab and chose a red background, so that the cell and text will really stand out.
- Click OK, to close the second dialog box. (You should be able to see a preview of how your new formatting will look, if you don't like it go back and make some changes.) Then, click OK on the first dialog box to return to your spreadsheet.
- Without moving the Excel cursor, copy the cell by hitting [CTRL]+[C] on your windows keyboard.
- Now, select the entire column by hitting [CTRL]+[SPACEBAR] on your windows keyboard.
- We will now paste this formatting to every cell in this column by choosing Edit, from the menu, then clicking on Paste Special...
- Select the Format option under the paste header, then click OK
Data Validation
This technique will prevent anyone from typing in any duplicate values at all. While this may seem the preferable way its drawback is it only works for someone typing in the cell, if they cut & paste the data validation will not work. So, this technique must be used in conjunction with conditional formatting. However, if they do a lot of manual typing to enter the values this is an extra layer of security to insure no human error. Here is the procedure to turn on data validation:- Go to the cell that will contain the key entry for your first record. (In this example we use row 1 for a header, and column A is where we are typing our key values. So, our first record will go on row 2, since 1 is for headers, making the cell we select A2)
- Select the Data menu, then Validation...
- On the Settings tab, change the Allow drop-down box to Custom.
- In the Formula box, enter this formula:=(COUNTIF(A:A,A2)>1=FALSE)
- Make sure the Ignore Blank check box has a check in it
- Click on the Error Alert tab
- Our error will be a Stop error, add an appropriate Title (like, Duplicate Data) and explain the error in the Error Message box (I wrote: "You have already used this value, please select another")
- Click OK
- Without moving the Excel cursor, copy the cell by hitting [CTRL]+[C] on your windows keyboard.
- Now, select the entire column by hitting [CTRL]+[SPACEBAR] on your windows keyboard.
- We will now paste this formatting to every cell in this column by choosing Edit, from the menu, then clicking on Paste Special...
- Select the Validation option under the paste header, then click OK
Subscribe to:
Posts (Atom)
