When I try to paste a long code into the data validation source, I am unable to do so. To solve this problem, I created a function in VBA, but after calling it in the data validation source, I keep getting the same error: A named range you specified cannot be found. I would like to create a dependent dropdown list using an IF condition or find another way to solve the issue.
This is the code I attempted to paste into the data validation source:
=IF(AND(B5="Single_Core", B7="Laid in Free Air", B8="Trefoil"), I3,
IF(AND(B5="Single_Core", B7="Laid in Free Air", B8="Flat"), I4,
IF(AND(B5<>"Single_Core", OR(B7="Laid in Free Air", B7="Laid in Duct")), i1,
IF(AND(B5="Single_Core", B7="Laid in Ground"), i2,
IF(AND(B5<>"Single_Core", B7="Laid Direct in Ground"), i2, "")))))
i1,i2,i3,i4 are defined in another sheet contain all lists
and this is the code i use it in the VBA Module:
Function InstallationType(B5 As String, B7 As String, B8 As String) As String
If B5 = "Single_Core" And B7 = "Laid in Free Air" And B8 = "Trefoil" Then
InstallationType = "I3"
ElseIf B5 = "Single_Core" And B7 = "Laid in Free Air" And B8 = "Flat" Then
InstallationType = "I4"
ElseIf B5 <> "Single_Core" And (B7 = "Laid in Free Air" Or B7 = "Laid in Duct") Then
InstallationType = "I1"
ElseIf B5 = "Single_Core" And B7 = "Laid in Ground" Then
InstallationType = "I2"
ElseIf B5 <> "Single_Core" And B7 = "Laid Direct in Ground" Then
InstallationType = "I2"
Else
InstallationType = ""
End If
End Function





