Bonjour,
Je suis en train de faire des listes déroulantes dans des colonnes différentes qui dépendent les une des autres. Je choisi une valeur dans une, cela me limite le choix dans une autre. J'ai réussi à faire cela entre 2 combobox et j'aurais aimé utilisé ma même fonction pour les 2 suivantes mais impossible. Le deuxième appel de la fonction ne fonctionne pas.
code qui passe les paramètres pour mes combobox
les combobox
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 Private Sub Worksheet_SelectionChange(ByVal Target As Range) On Error GoTo errorHandler Debug.Print "Worksheet_SelectionChange(" & Target.Address & ")" ' if more than 1 cell => do nothing If Target.Count > 1 Then GoTo exitHandler If CtrlNamesIsSet = False Then PopulateCtrlNames PopulateClientsCollection CtrlNamesIsSet = True End If Application.EnableEvents = False 'disable events (key down, ...) HideAllComboBox ColumnSelector Target Application.EnableEvents = True 'enable events (key down, ...) exitHandler: Application.EnableEvents = True Exit Sub errorHandler: Resume exitHandler End Sub
la fonction
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 Private Sub ColumnSelector(ByVal Target As Range) Debug.Print "ColumnSelector(" & Target.Address & ")" Select Case Target.Column Case 2 'client showComboBox CtrlNames(2), Target, GetDataRangeAddress("B") Case 4 'projet 'showComboBox CtrlNames(4), Target, GetDataRangeAddress("E") showComboBox CtrlNames(4), Target, GetDataRangeAddressByFilter("E", "D", ClientsCollection.Item(ActiveSheet.Range("B" & Target.Row))) Case 5 'tache 'showComboBox CtrlNames(5), Target, GetDataRangeAddress("L") showComboBox CtrlNames(5), Target, GetDataRangeAddressByFilter("L", "K", ClientsCollection.Item(ActiveSheet.Range("F" & Target.Row))) Case 6 'activity showComboBox CtrlNames(6), Target, GetDataRangeAddress("I") End Select End Sub
merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 Private Function GetDataRangeAddressByFilter(Col As String, FilterCol As String, FilterValue As String) Debug.Print "GetDataRangeAddressByFilter(" & Col & ", " & FilterCol & ", " & FilterValue & ")" Dim Result As String Result = "" If FilterValue = "" Then Result = GetDataRangeAddress(Col) GetDataRangeAddressByFilter = Result Exit Function End If Dim StartRow As Integer Dim StopRow As Integer StartRow = 0 StopRow = 0 Dim DataSheet As Worksheet Set DataSheet = ThisWorkbook.Sheets(2) Dim numberOfRows As Integer numberOfRows = WorksheetFunction.CountA(DataSheet.Range(Col & "2:" & Col & "1000")) Dim i As Integer Dim FilterStr As String FilterStr = FilterValue & "." For i = 2 To numberOfRows + 1 If Left(DataSheet.Range(FilterCol & i), Len(FilterStr)) = FilterStr Then If StartRow = 0 Then StartRow = i If StopRow = 0 Or StopRow < i Then StopRow = i End If Next i Result = "data!" & DataSheet.Range(Col & StartRow).Address & ":" & DataSheet.Range(Col & StopRow).Address Debug.Print "range = " & Result GetDataRangeAddressByFilter = Result End Function
seba_stien
Partager