(I am using Excel in french)
I am updating and cleaning a worksheet with validation dropdown.
The values from these dropdown come from one of the 32 named ranges of the worksheet (ListeOP, Liste1000, Liste2000, etc.) depending other cells.
Currently the cells validation is:
- Authorize: List
- Source (unfold) :
=INDIRECT(
SI(
ET(A8<>"";A8=B8);
"ListeOP";
SI(
A7<>"";
CONCATENER(
"Liste";
A7
);
SI(
A8=B8;
"ListeOP";
CONCATENER(
"Liste";
A8
)
)
)
)
)
This work but is really inreadable and difficult ton maintain. I wanted to create a VBA function to determine which named range to use.
Public Function GetActivityComboBox(activity As Integer, family As Integer, familyTop As Integer) As String
If (family > 0 And activity = family) Then
GetActivityComboBox = "ListeOP"
ElseIf (familyTop > 0) Then
GetActivityComboBox = "Liste" & familyTop
ElseIf (family = activity Or family = 0) Then
GetActivityComboBox = "ListeOP"
Else
GetActivityComboBox = "Liste" & family
End If
End Function
And the new validation source:
=INDIRECT(GetActivityComboBox(B8;A8;A7))
But I get the error: Impossible to find the named range you specify (translation)
I already checked my VBA function returns the right range name.
What did I miss ? or does anyone has another idea to obtain the same behavior (in few words: variable validation list)