Search Contextures Sites ![]()
Excel Data Validation -- Hide Previously Used Items in Dropdown
Thanks to Excel MVP, Peo Sjoblom, who contributed the original formula for this technique, and to Daniel.M, who suggested the enhanced formulas.
Set up the Main Table
Create the List of Items
Create the Excel Data Validation List
Apply the Excel Data Validation
Test the Excel Data Validation
Dependent Data Validation
To download a zipped sample file, click here:
Excel Data Validation -- Hidden Items -- Sample
You can limit the choices in an Excel Data Validation list, hiding items that have been previously selected. For example, if you are assigning employees to a shift, you want to avoid assigning the same employee twice.In the dropdown list, the names that have been used are removed.
=IF(COUNTIF(Schedule!$B$2:$B$7,A1)>=1,"",ROW())
2. Copy the formula down to cell B6.
This formula counts the occurrences of "Bert" in cells B2:B7 on the Schedule worksheet. If the count is greater than or equal to 1, the cell will appear blank. Otherwise, the row number will be displayed.
B) Create the list of unused names
The next step is to create a multi-cell array formula which will move any blank cells to the end of the list.
- Select cells C1:C6
- Enter the following array formula (the formula is long, and should be all on one line)
=IF(ROW(A1:A6)-ROW(A1)+1>COUNT(B1:B6),"",
INDEX(A:A,SMALL(B1:B6,ROW(INDIRECT("1:"&ROWS(A1:A6))))))
3. Press Ctrl+Shift+Enter to enter the array formula in cells C1:C6
Single-Cell Formula Alternative
If you'd prefer a single-cell formula (easier to edit), you could use this formula, also by Daniel.M. He recommends it for small ranges (<=200 cells):
- Select cell C1
- Enter the following formula (the formula is long, and should be all on one line)
=IF(ROW(A1)-ROW(A$1)+1>COUNT(B$1:B$6),"",
INDEX(A:A,SMALL(B$1:B$6,1+ROW(A1)-ROW(A$1))))- Press Enter
- Copy the formula down to row 6
Name the Excel Data Validation List
1. Choose Insert>Name>Define
2. In the Names in workbook box, type a one-word name for the range, e.g. NameCheck.
3. In the Refers to box, type the following formula (all on one line):=OFFSET(Employees!$C$1,0,0,COUNTA(Employees!$C$1:$C$6)-COUNTBLANK(Employees!$C$1:$C$6),1)
4. Click OK
Contextures Inc., Copyright © 2009.
All rights reserved.
Last updated: October 13, 2009 11:23 PM