Appel fonction création combobox depuis un Private Sub UserForm_Initialize
Bonjour,
Je voudrais faire appel à une fonction pour gérer plusieurs COMBOBOX similaires
Comme d'habitude ma requête est floue. Donc je vais mettre la procédure qui fonctionne :
Code:
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
| 'Private Sub UserForm_Initialize()
'
' Me.ComboExercice.Clear
'
' With Worksheets(2)
' For Each C In Range(Cells(DEBLIG + 4, DEBCOL + 5), Cells(DerLig, DEBCOL + 5).End(xlDown))
' ComboExercice = C
' If ComboExercice.ListIndex = -1 And ComboExercice <> "" Then ComboExercice.AddItem C
' Next C
' End With
' On Error Resume Next
'
' With ComboExercice
' For i = 0 To .ListCount - 1
' For j = 0 To .ListCount - 1
' If .List(i) < .List(j) Then
' Temp = .List(i)
' .List(i) = .List(j)
' .List(j) = Temp
' End If
' Next j
' Next i
'
' .ListIndex = -1
'
' End With
'
'End Sub |
la fonction:
Code:
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
| Function AppelForm(NomCombo, Colonne, Ligne)
Me.Controls("Combo" & NomCombo).Clear
With Worksheets(2)
For Each C In Range(Cells(Ligne, Colonne), Cells(DerLig, Colonne).End(xlDown))
Me.Controls("Combo" & NomCombo) = C
If Me.Controls("Combo" & NomCombo).ListIndex = -1 And Me.Controls("Combo" & NomCombo) <> "" Then Me.Controls("Combo" & NomCombo).AddItem C
Next C
End With
On Error Resume Next
With Me.Controls("Combo" & NomCombo)
For i = 0 To .ListCount - 1
For j = 0 To .ListCount - 1
If .List(i) < .List(j) Then
Temp = .List(i)
.List(i) = .List(j)
.List(j) = Temp
End If
Next j
Next i
.ListIndex = -1
End With
End Function |
et ce que je voudrais obtenir :
Code:
1 2 3
| Private Sub UserForm_Initialize()
Call AppelForm(Exercice, 6, 5)
End Sub |
Exercice est le nom de ma combox box
6 est la colonne
5 est la ligne
lorsque je lance j'obtiens une erreur de compilation.....