Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Intersect(Target, Range("B20:B20")) Is Nothing Then
Target.Offset(0, 1) = "Please Select"
Target.Offset(0, 2) = "Please Select"
Target.Offset(0, 3) = "Please Select"
End If
''If Not Intersect(Target, Range("H4:H20")) Is Nothing Then
''Target.Offset(0, 1) = ""
''End If
''If Not Intersect(Target, Range("I4:I20")) Is Nothing Then
''Target.Offset(0, 1) = ""
''End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo line1
'First Level**********
If Not Intersect(Target, Range("B20:B20")) Is Nothing Then
Application.EnableEvents = False
Dim FstRng As Range, cel As Range
Dim FstStr As String, FstVal As String
Set FstRng = Worksheets("Name of sheet").Range("A15:A309")
For Each cel In FstRng
If InStr(1, FstStr, "," & cel & ",") = 0 Then
FstStr = FstStr & "," & cel & ","
FstVal = FstVal & "," & cel
End If
Next cel
If FstVal <> "" Then FstVal = Mid(FstVal, 2)
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=FstVal
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
'Application.EnableEvents = True
End If
'Second Level***************************
If Not Intersect(Target, Range("C20:C20")) Is Nothing Then
Application.EnableEvents = False
Dim SecRng As Range, cel1 As Range
Dim SecStr As String, SecVal As String
Set SecRng = Worksheets("Name of sheet").Range("B15:B309")
For Each cel1 In SecRng
If InStr(1, SecStr, "," & cel1 & ",") = 0 And cel1.Offset(0, -1) = Target.Offset(0, -1) Then
SecStr = SecStr & "," & cel1 & ","
SecVal = SecVal & "," & cel1
End If
Next cel1
If SecVal <> "" Then SecVal = Mid(SecVal, 2)
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=SecVal
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Application.EnableEvents = True
End If
'Third Level*********
If Not Intersect(Target, Range("D20:D20")) Is Nothing Then
Application.EnableEvents = False
Dim ThiRng As Range, Cel2 As Range
Dim ThiStr As String, ThiVal As String
Set ThiRng = Worksheets("Name of sheet").Range("C15:C309")
For Each Cel2 In ThiRng
If InStr(1, ThiStr, "," & Cel2 & ",") = 0 And Cel2.Offset(0, -1) = Target.Offset(0, -1) _
And Cel2.Offset(0, -2) = Target.Offset(0, -2) Then
ThiStr = ThiStr & "," & Cel2 & ","
ThiVal = ThiVal & "," & Cel2
End If
Next Cel2
If ThiVal <> "" Then ThiVal = Mid(ThiVal, 2)
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=ThiVal
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Application.EnableEvents = True
End If
line1:
Application.EnableEvents = True
End Sub
This is your code but modified based on the actual needs. The results are that only the first choice cell has a drop down list and the others don't. Also the drop down list with the
Bookmarks