liste déroulante classée par ordre aphabétique

  • Initiateur de la discussion Initiateur de la discussion kikie43
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

kikie43

XLDnaute Nouveau
Bonjour à tous.

Je résume
j'ai un tableau qui est rempli de façon aléatoire.
J'ai créé un combobox afin d'avoir une liste déroulante supprimant les lignes vides.
Jusque là c'est ok.
Mais je souhaite que cette liste soit classée par ordre alphabétique et là, j'ai eu beau tourner le code dans tout les sens ... Je ne suis arrivée à rien.
Code:
Sub listederoulante()

Dim tablo(1 To 9)
Dim j As Integer

tablo(1) = Range("A4:A28").Value
tablo(2) = Range("A31:A58").Value
tablo(3) = Range("A61:A88").Value
tablo(4) = Range("A91:A118").Value
tablo(5) = Range("A122:A148").Value
tablo(6) = Range("A151:A178").Value
tablo(7) = Range("A181:A208").Value
tablo(8) = Range("A211:A238").Value
tablo(9) = Range("A241:A267").Value

For I = 1 To 9
    For a = 1 To UBound(tablo(I))
        If tablo(I)(a, 1) <> "" Then ComboBox1.AddItem tablo(I)(a, 1)
    Next
Next



 End Sub
Voici mon code.
Est ce que quelqu'un aurait une solution ou une piste ?
Je vous remercie
Cordialement
 
Re : liste déroulante classée par ordre aphabétique

Bonjour kiekie43

Et bienvenue sur XLD

A tester:
NB : tri ascendant (pour tri descendant mettre < au lieu de > dans If tablo(m, 1) > tablo(n, 1) Then

Code:
Sub listederoulante()


Dim tablo(1 To 9)
Dim j As Integer


tablo(1) = Range("A4:A28").Value
tablo(2) = Range("A31:A58").Value
tablo(3) = Range("A61:A88").Value
tablo(4) = Range("A91:A118").Value
tablo(5) = Range("A122:A148").Value
tablo(6) = Range("A151:A178").Value
tablo(7) = Range("A181:A208").Value
tablo(8) = Range("A211:A238").Value
tablo(9) = Range("A241:A267").Value


For I = 1 To 9
    For a = 1 To UBound(tri(tablo(I)))
        If tri(tablo(I)(a, 1)) <> "" Then ComboBox1.AddItem tri(tablo(I)(a, 1))
    Next
Next
End Sub


Function tri(tablo)
For n = LBound(tablo, 1) To UBound(tablo, 1)
  For m = LBound(tablo, 1) To UBound(tablo, 1)
    If tablo(m, 1) > tablo(n, 1) Then
      temp = tablo(m, 1)
      tablo(m, 1) = tablo(n, 1)
      tablo(n, 1) = temp
    End If
  Next
Next
tri = tablo
End Function
 
Re : liste déroulante classée par ordre aphabétique

Bonjour,

Listes Triées

Code:
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:A267")
    If c.Value <> "" Then MonDico.Item(c.Value) = ""
  Next c
  temp = MonDico.Keys
  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

Avec la méthode proposée (compliquée)

Code:
Option Compare Text
Private Sub UserForm_Initialize()
Dim tablo(1 To 9)
Dim j As Integer
Dim temp()
tablo(1) = Range("A4:A28").Value
tablo(2) = Range("A31:A58").Value
tablo(3) = Range("A61:A88").Value
tablo(4) = Range("A91:A118").Value
tablo(5) = Range("A122:A148").Value
tablo(6) = Range("A151:A178").Value
tablo(7) = Range("A181:A208").Value
tablo(8) = Range("A211:A238").Value
tablo(9) = Range("A241:A267").Value

For I = 1 To 9
    For a = 1 To UBound(tablo(I))
        If tablo(I)(a, 1) <> "" Then ComboBox1.AddItem tablo(I)(a, 1)
    Next
Next
temp = ComboBox1.List
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, 0)
 g = gauc: d = droi
 Do
     Do While a(g, 0) < ref: g = g + 1: Loop
     Do While ref < a(d, 0): d = d - 1: Loop
     If g <= d Then
       temp = a(g, 0): a(g, 0) = a(d, 0): a(d, 0) = 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

JB
 

Pièces jointes

Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
771
Retour