Trier combobox avec valeurs numériques [RESOLU]

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

  • raccordtest.zip
    377.1 KB · Affichages: 45
Dernière édition:

goldfinger13

XLDnaute Occasionnel
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
 

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
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

  • Copie de raccordtest.zip
    389.2 KB · Affichages: 39
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 291
Messages
2 086 849
Membres
103 400
dernier inscrit
MINOU WILL