View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
vezerid
 
Posts: n/a
Default display a drop-down list based on the content of another cell

Joe,
without VBA you can have a Custom data validation with the following
formula:
=IF(A1<100, B1="", OR(B1="a", B1="b", B1="c"))

This option, however, will not display a drow-down. Your other option
is to use the Worksheet_Change event macro to track changes in A1 (or
whatever the discriminant cell is).

Private Sub Worksheet_Change(ByVal Target As Range)
If not intersect(target, range("a1")) is nothing then
if range("a1").value < 100 then
with range("B1").validation
.Delete
.Add Type:=xlValidateTextLength, AlertStyle:=xlValidAlertStop,
_
Operator:=xlEqual, Formula1:="0"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
else
with range("b1").validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=$F$1:$F$3"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
end with
end if
end if
End Sub

This code was partly produced by the marco recorder. Change range("a1")
and range("b1") to whatever cells necessary.
To use this code right-click on the sheet tab, select View Code and
this will take you to the sheet module in VBA. Paste this code.

HTH
Kostis Vezerides