I have a worksheet UserEntry with 2 columns, Block and Address. I want to validate both of these based on another worksheet Validation with the same column names. The data on the Validation sheet is as follows:
Block | Address
---------------
001 | 101
001 | 101.3
001A | 35
020-1 | 203
020-1 | 203.5
020-1 | 204.1
...
There are about 11000 different blocks, and about 40000 block/address pairs.
My goal is that if a user enters a value into the Block column on the UserEntry sheet, the drop-down choices in the Address column change to correspond with that Block.
I tried using Custom validation with this formula:
=VLOOKUP(UserEntry!A2,Validation!A2:B40000)
But that evaluated to an error. I saw some solutions in various forums that involved setting named ranges and then having the VLOOKUP() search for the appropriate named range, but it seems like that won’t work here because I’d have to create 11000 named ranges.
How can I make the validation drop-down for Address include all the values corresponding to a given Block value?
You didn’t mention VBA but here is a solution that uses it.
Step 1
Create a master table of Block-Address relationships. Make sure this is sorted on
Block. I used Sheet1:Cell
E2is important. You don’t actually have to put anything there, but the macro will use it. CellE3is for show only, but you will use the formula (which is commented out here so you can see it) momentarily.Step 2
Create a named range. The formula in
Refers to:is what you saw inE3above, and you can see the reference to cellE2here. The formula for your convenience isStep 3
Set up a new worksheet (Sheet2) where the data entry will happen. Create data validation for the
Addresscolumn as shown.Step 4
Open the VBA editor and paste this code in the module for
Sheet2. You can remove theDebugstatement if you wish. Again note the reference to cellE2onSheet1:Step 5
Enjoy. Your data validation is now context sensitive. Examples: