Data validation list conotrols other DV list

staticbob

Well-known Member
Joined
Oct 7, 2003
Messages
1,079
Hi,

I need a data validation list to populate another list.

I have this example that works on the data at the top left. Cell G12 is a data validation list that looks at row 1. Using the code below, the 2nd validation list (I2) then only shows the users at that site.

This works well. My problem is that I need this to work on the data format shown in A15:A25, not on the table format.

Any ideas ?

Thanks in advance
Bob
Dynamic data Val.xls
ABCDEFGHI
1SiteASiteBSiteC
2JimKidMike
3JohnKurtMark
4JoeKim
5JerryKelly
6Kristen
7
8
9
10
11SiteName
12SiteAJoe
13
14
15SiteAJim
16SiteAJohn
17SiteAJoe
18SiteAJerry
19SiteBKid
20SiteBKurt
21SiteBKim
22SiteBKelly
23SiteBKristen
24SiteCMike
25SiteCMark
Blad1


Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim DataCol As String, DataR As String

If Target.Address = "$G$12" Then
DataCol = Cells(2, WorksheetFunction.Match(Range("G12").Value, Rows(1), 0)).Address
DataR = Range(DataCol, Range(DataCol).End(xlDown)).Address

Range("I12").Value = ""

With Range("I12").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="=" & DataR
.IgnoreBlank = True
.InCellDropdown = True
.ErrorTitle = " Unacceptable input."
.ErrorMessage = "Pick an item out of the list."
.ShowError = True
End With
End If

End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Thanks JPG,

Thats works great, but . . . . the named ranges are dynamic and change daily. I may have upto 250 different sites each day, each with upto 50 users. I would need to redefine 300 named ranges daily.

Could this still be done without code ?

Thanks in advance
Bob
 
Upvote 0
Ok, this is a more dynamic way, without code.

Assuming sheets like this:
Book1
ABCD
1SiteASiteBSiteC
2JimKidMike
3JohnKurtMark
4JoeKim
5JerryKelly
6Kristen
7
8
Lists


and
Book1
ABCD
1SiteName
2SiteA
3SiteA
4SiteA
5SiteA
6SiteB
7SiteC
8SiteB
9SiteB
10SiteB
11SiteC
12SiteC
Sheet2


where you define the appropiate sites with their names in the sheet 'Lists'.

Now, in Sheet 2, select cell B2, and define the following names (Insert | Name, Define...)

Code:
BigStr	=REPT("z",255)
Col	=MATCH(Sheet2!$A2,Lists!$1:$1,0)
List	=INDEX(Rng,2):INDEX(Rng,MATCH(BigStr,Rng))
Rng	=INDEX(Lists!$1:$65536,0,Col)
Sites	=Lists!$A$1:INDEX(Lists!$1:$1,MATCH(BigStr,Lists!$1:$1))

Now, select column A (still in Sheet 2), and go to Data | Validation. Select "List" and in the source box put

=Sites

Now, select column B, go to Data | Validation again, select "List" and in the source put

=List

and you should be set.
 
Upvote 0
I didn't study yet Juan's proposal. An advantage of Juan's proposal is that it does not contain volatile functions compared to what follows...
DynamicSublists.xls
ABCD
1$B$3:$B$6$C$3:$C$7$D$3:$D$4
2MainSiteASiteBSiteC
3SiteAJimKidMike
4SiteBJohnKurtMark
5SiteCJoeKim
6JerryKelly
7Kristen
8
AdminLists


We need two definitions which must be done using Insert|Name|Define.

Activate Insert|Name|Define.
Enter BigStr as name in the box for Names in Workbook.
Enter the following in the Refers to Box:

=REPT("z",255)

Click Add.

Enter MainList as name in the box for Names in Workbook.
Enter the following in the Refers to Box:

=AdminLists!$A$3:INDEX(AdminLists!$A:$A,MATCH(BigStr,AdminLists!$A:$A))

Click OK.

The following steps define the dependent sublists using the Name Box on the Formula Bar. Since your site names can contain spaces, we must take that into account.

In B1 enter & copy across:

=ADDRESS(ROW(B3),COLUMN(B3))&":"&ADDRESS(MATCH(BigStr,B:B),COLUMN(B3))

Activate B1, go to the Name Box on the Formula Bar, type SiteA (without a space between "Site" and "A"), and hit enter. Repeat this procedure for Site B and Site C using C1 and D1.

Now you can set up on some sheet, say, Sheet2, data validation using the foregoing definitions...

Example: Let A2 and B2 on Sheet2 be the cells where we want to data validate...

Activate A2.
Activate Data|Validation.
Choose List for Allow.
Enter the following in the Source box:

=MainList

Click OK.

This gives us the main list from which to choose a site.

Activate B2.
Activate Data|Validation.
Choose List for Allow.
Enter the following in the Source box:

=INDIRECT(INDIRECT(SUBSTITUTE(A2," ","")))

Note the second round of evaluation with INDIRECT.

Click OK.

In B2 we get a sublist to choose from, which is dependent on the choice made in A2.
 
Upvote 0
Sorry Gents,

I have confused things with my original exhibit. My data actually appears in this format . . .
Book1
ABCD
1SiteAJohn
2SiteBGeoff
3SiteCJayne
4SiteBClare
5SiteBSteven
6SiteAPaul
7SiteCHumphrey
8SiteACilla
9SiteBJack
10SiteCDave
11SiteBEmma
12SiteBMax
13SiteASteffan
14SiteCSarah
15SiteASue
16SiteBLee
17SiteCPete
18SiteBRobin
19SiteBGaylord
20SiteABill
Sheet1


I need one drop down list to select the Site, then another dropdown list to select from users on at that site.

The main problem is that this list is going to be dynamic, changing potentially each day. I could have 250 sites, each with 50 or so users.

Thanks again,
Bob
 
Upvote 0
I have a method that uses another worksheet. Computationally it isn't the best but it does the job. Would you like me to send it to you? PM ur email if you do.
 
Upvote 0
staticbob said:
Sorry Gents,

I have confused things with my original exhibit. My data actually appears in this format . . .

For one thing, it requires a lot more processing...

I need one drop down list to select the Site, then another dropdown list to select from users on at that site.

The main problem is that this list is going to be dynamic, changing potentially each day. I could have 250 sites, each with 50 or so users...

Not that difficult to construct/adapt the system I already posted, but the sheer amount od sites would render ineeficient.

I were you, I'd study Bolo's offer. Another possibility that comes to mind is macros that use Advanced Filter to construct the required lists, which can be combined with the system I already proposed.
 
Upvote 0
Hi all,
I used Juan's method to do the dependent list. It works.

But when I tried using it cross workbook, it cannot work.

Could anyone advise me how to use the dynamic range across the workbooks?

Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,340
Messages
6,124,382
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top