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
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
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | SiteA | SiteB | SiteC | ||||||||
2 | Jim | Kid | Mike | ||||||||
3 | John | Kurt | Mark | ||||||||
4 | Joe | Kim | |||||||||
5 | Jerry | Kelly | |||||||||
6 | Kristen | ||||||||||
7 | |||||||||||
8 | |||||||||||
9 | |||||||||||
10 | |||||||||||
11 | Site | Name | |||||||||
12 | SiteA | Joe | |||||||||
13 | |||||||||||
14 | |||||||||||
15 | SiteA | Jim | |||||||||
16 | SiteA | John | |||||||||
17 | SiteA | Joe | |||||||||
18 | SiteA | Jerry | |||||||||
19 | SiteB | Kid | |||||||||
20 | SiteB | Kurt | |||||||||
21 | SiteB | Kim | |||||||||
22 | SiteB | Kelly | |||||||||
23 | SiteB | Kristen | |||||||||
24 | SiteC | Mike | |||||||||
25 | SiteC | Mark | |||||||||
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