VBA: Liste déroulante

Résolu
TeddyGalere Messages postés 75 Date d'inscription   Statut Membre Dernière intervention   -  
 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

2 réponses

ccm81 Messages postés 10909 Date d'inscription   Statut Membre Dernière intervention   2 433
 
Bonjour

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
0
TeddyGalere
 
Yes !!!
Merci beaucoup...
Rapide et efficace ;)
0
Boisgontierjacques Messages postés 175 Date d'inscription   Statut Membre Dernière intervention   64
 
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
0