I would like to create a dropdown in Excel on Sheet1 if in the row any cells conatins a an expression (Here is the example of "PBE"), then an extended dropdown list will be available.
(The extension worked without if)
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
Dim a$, el As Range
Dim a1 As Range
Dim rng1 As Range, rng2 As Range
Set rng1 = Worksheets("OptionList").Range("E8:E48") 'Base list
Set rng2 = Worksheets("OptionList").Range("K2:K3") 'IF in the row the list contains PBE add to the selection this list as
If Not Intersect(Target, Target.Worksheet.Range("A2")) Is Nothing Then
For Each el In rng1 'first range
a = a & el.Value & ","
Next
For Each el In rng2 '2nd range but only if the row contains
a1 = a & el.Value & ","
Next
For i = 68 To 78
If Worksheets("Sheet1").Range(Cells(i, 19), Cells(i, 48)).Find("PBE") Is Nothing Then
With Worksheets("Sheet1").Range(Cells(i, 19), Cells(i, 48)).Validation 'destination val.list (without PBA)
.Delete
.Add Type:=xlValidateList, Formula1:=a
End With
Else
With Worksheets("Sheet1").Range(Cells(i, 19), Cells(i, 48)).Validation 'destination val.list with PBA
.Delete
.Add Type:=xlValidateList, Formula1:=a1
End If
Next i
End If
Set rng1 = Nothing
Set rng2 = Nothing
End Sub
It is not working line by line, but for all the lines which are targeted by i. So I mean if anywere in the big range there is a PBE word not line, by line it trigers the exteneded dropdown menu.