VBA: Liste déroulante
Résolu
TeddyGalere
Messages postés
77
Statut
Membre
-
TeddyGalere -
TeddyGalere -
Salut la communauté !!
J'ai un petit soucis...
Je souhaite dans un UserForm insérer une liste déroulante qui comprend les cellules d'une colonne d'un tableau.
Jusque là, pas de soucis, ma formule me donne ca:
Private Sub UserForm_Initialize()
Dim Derlig As Byte, Cptr As Byte
With Sheets("recap")
'remplit le combo avec libellés existant
Derlig = .Range("a50000").End(xlUp).Row
For Cptr = 6 To Derlig
ComboBox_choix.AddItem .Cells(Cptr, "D") <> ""
Next
End With
End Sub
Cependant dans ce tableau, j'ai des champs qui sont vide et donc ma liste ressemble a un truc du style:
Albert
Francois
Nicolas
Jules
Matthieu
Paul
Henri
Julie (sinon on va dire que je suis sexiste^^)
Donc ma question est: Quel bout de code je pourrai intégrer pour faire sauter les blancs entre les différents éléments???
En vous remerciant
J'ai un petit soucis...
Je souhaite dans un UserForm insérer une liste déroulante qui comprend les cellules d'une colonne d'un tableau.
Jusque là, pas de soucis, ma formule me donne ca:
Private Sub UserForm_Initialize()
Dim Derlig As Byte, Cptr As Byte
With Sheets("recap")
'remplit le combo avec libellés existant
Derlig = .Range("a50000").End(xlUp).Row
For Cptr = 6 To Derlig
ComboBox_choix.AddItem .Cells(Cptr, "D") <> ""
Next
End With
End Sub
Cependant dans ce tableau, j'ai des champs qui sont vide et donc ma liste ressemble a un truc du style:
Albert
Francois
Nicolas
Jules
Matthieu
Paul
Henri
Julie (sinon on va dire que je suis sexiste^^)
Donc ma question est: Quel bout de code je pourrai intégrer pour faire sauter les blancs entre les différents éléments???
En vous remerciant
A voir également:
- VBA: Liste déroulante
- Excel compter cellule couleur sans vba - Guide
- Dépassement de capacité vba ✓ - Forum Excel
- Incompatibilité de type vba ✓ - Forum VB / VBA
- Erreur 13 incompatibilité de type VBA excel ✓ - Forum Excel
- Vba range avec variable ✓ - Forum VB / VBA
2 réponses
Bonjour
Ceci dvrait aller
Cdlmnt
Ceci dvrait aller
Private Sub UserForm_Initialize()
Dim Derlig As Byte, Cptr As Byte
With Sheets("recap")
'remplit le combo avec libellés existant
Derlig = .Range("D" & Rows.Count).End(xlUp).Row
For Cptr = 6 To Derlig
If .Cells(Cptr, "D") <> "" Then ComboBox_choix.AddItem .Cells(Cptr, "D")
Next
End With
End Sub
Cdlmnt
Bonjour,
Liste sans vides triée
http://boisgontierjacques.free.fr/pages_site/formulairelistetriee.htm#Dictionary
http://boisgontierjacques.free.fr/fichiers/Formulaire/FormListeTrieeVides.xls
Option Compare Text
Private Sub UserForm_Initialize()
Dim temp()
Set f = Sheets("BD")
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("A2:A" & f.[A65000].End(xlUp).Row)
If c.Value <> "" Then MonDico.Item(c.Value) = c.Value
Next c
temp = MonDico.items
Call tri(temp, LBound(temp), UBound(temp))
Me.ComboBox1.List = temp
End Sub
Sub tri(a(), gauc, droi) ' Quick sort
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub
Boisgontier
Liste sans vides triée
http://boisgontierjacques.free.fr/pages_site/formulairelistetriee.htm#Dictionary
http://boisgontierjacques.free.fr/fichiers/Formulaire/FormListeTrieeVides.xls
Option Compare Text
Private Sub UserForm_Initialize()
Dim temp()
Set f = Sheets("BD")
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("A2:A" & f.[A65000].End(xlUp).Row)
If c.Value <> "" Then MonDico.Item(c.Value) = c.Value
Next c
temp = MonDico.items
Call tri(temp, LBound(temp), UBound(temp))
Me.ComboBox1.List = temp
End Sub
Sub tri(a(), gauc, droi) ' Quick sort
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call tri(a, g, droi)
If gauc < d Then Call tri(a, gauc, d)
End Sub
Boisgontier
Merci beaucoup...
Rapide et efficace ;)