Trier combobox avec valeurs numériques [RESOLU]

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 !

goldfinger13

XLDnaute Occasionnel
Bonjour à tous

je cherche à trier les valeurs de mes deux Combobox en ordre croissant sans pour autant toucher à l'ordre de la BASE.

et bien évidemment je tourne en rond donc je vous sollicite
merci d'avance pour votre aide
 

Pièces jointes

Dernière édition:
Re : Trier combobox avec valeurs numériques

J'ai transformé mon code ainsi mais là par contre j'ai des doublons

Code:
Private Sub UserForm_Initialize()
  Dim f As Worksheet
  Set f = Sheets("Base")
  Me.ComboBox1.List = Range(f.[d2], f.[d2].End(xlDown)).Value
  Application.ScreenUpdating = False
  Sheets.Add
  [d1].Resize(ComboBox1.ListCount) = ComboBox1.List
  [d2:d65000].Sort Key1:=[d:d], Order1:=xlAscending, Header:=xlGuess
  Me.ComboBox1.List = [d1].Resize(ComboBox1.ListCount).Value
  Application.DisplayAlerts = False
  ActiveSheet.Delete
  Application.ScreenUpdating = True
End Sub

help svp
 
Re : Trier combobox avec valeurs numériques

Bonsoir,


Code:
Private Sub UserForm_Initialize()
  Dim i As Integer
  Dim j As Integer
  Dim f, mondico, a, temp()
  Set f = Sheets("BASE")
  Set mondico = CreateObject("Scripting.Dictionary")
  a = f.Range("D2:D" & f.[A65000].End(xlUp).Row)   ' tableau a(n,1) pour rapidité
  For i = LBound(a) To UBound(a)
    If a(i, 1) <> "" Then mondico(a(i, 1)) = Val(a(i, 1))
  Next i
  '--avec tri
  temp = mondico.items
  Call Tri(temp, LBound(temp), UBound(temp))
  Me.ComboBox1.List = temp
  Me.ComboBox2.List = temp
End Sub

Sub Tri(a, gauc, droi) ' Quick sort
  Dim ref, g, d, temp
  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

JB
Formation Excel VBA 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

  • Question Question
Microsoft 365 problème d'index
Réponses
19
Affichages
498
Réponses
12
Affichages
408
Réponses
40
Affichages
2 K
Réponses
3
Affichages
256
Réponses
6
Affichages
371
Retour