Here is a very simple example using VBA
Place this event macro in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A1 As Range, B1 As Range
Set A1 = Range("A1")
Set B1 = Range("B1")
If Intersect(A1, Target) Is Nothing Then Exit Sub
Select Case A1.Value
Case "animals"
Call SetupDV(B1, "dog,cat,bird")
Case "days"
Call SetupDV(B1, "monday,tuesday,wednesday")
Case "months"
Call SetupDV(B1, "january,february,march")
End Select
End Sub
and place this macro in a standard module:
Sub MAIN()
Cells.Validation.Delete
Call SetupDV(Range("A1"), "animals,days,months")
End Sub
Sub SetupDV(MyCells As Range, st As String)
With MyCells.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=st
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
Then run MAIN
Whenever you make a selection from the pull-down in cell A1, the pull-down in cell B1 will adjust accordingly:
INDIRECT
? This is one of the more common use cases forINDIRECT
, and it usually works well if you name the ranges correctly. – Byron Wall