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 can use a dynamic named range for this.
Assumptions:
Validation!A:B
UserEntry
theAddress
cell to be validated is one cell to the right of the entedBlock
Create a Named Range to use as validation source (I've used name
ValList
):Add Data Validation to the required cells: Allow
List
, Source=ValList
INDIRECT
,ADDRESS
andCELL
to get a refernce to the user entered Block relative to the active cellMATCH
andCOUNTIF
to get the position and size of the matching Blocks in the validation listOFFSET
to set the return range to the addreesses matching the enterd blockYou 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
E2
is important. You don't actually have to put anything there, but the macro will use it. CellE3
is 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 inE3
above, and you can see the reference to cellE2
here. The formula for your convenience isStep 3
Set up a new worksheet (Sheet2) where the data entry will happen. Create data validation for the
Address
column as shown.Step 4
Open the VBA editor and paste this code in the module for
Sheet2
. You can remove theDebug
statement if you wish. Again note the reference to cellE2
onSheet1
:Step 5
Enjoy. Your data validation is now context sensitive. Examples: