IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Trie Alpha combobox [XL-2007]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Inscrit en
    Septembre 2008
    Messages
    629
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 629
    Par défaut Trie Alpha combobox
    Bonjour,

    J'ai un USF, comprenant TextBox et ComBobox je suis à la recherche d'un code pour trie alpha dans une ComBobox

    Un très grand merci à tout ceux qui pourront m'aider...

    Ci-dessous mon code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    ' Chois par Combobox
    Private Sub Combobox1_Click()
            Dim lign As Long
            If ComboBox1.Value <> "" Then
     
            lign = ComboBox1.ListIndex + 3
            txtPrenom.Value = Range("b" & lign).Value
            TextTel.Value = Range("c" & lign).Value
            TextMob.Value = Range("d" & lign).Value
            TextBur.Value = Range("e" & lign).Value
            TextFax.Value = Range("f" & lign).Value
            txtAdresse.Value = Range("g" & lign).Value
            txtCp.Value = Range("h" & lign).Value
            txtCommune.Value = Range("i" & lign).Value
            'txtDepartement.Value = Range("j" & lign).Value
            'TextBox3.Value = Range("k" & lign).Value 'Email
     
        End If
         txtNom.Value = ComboBox1.Value ' Copie combobox vers txtPrenom
    End Sub
     
    Private Sub CommandButton1_Click()
    Unload Me
    End Sub
     
    Private Sub UserForm_Initialize()
     
        Dim Cell As Range
        With Sheets("Repertoire")
            For Each Cell In .Range("A3:A" & .Range("A65536").End(xlUp).Row)
                Me.ComboBox1.AddItem (Cell)
            Next
     
    End Sub
    Cordialement
    Max

  2. #2
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    En utilisant l'algorithme de tri rapide QuickSort
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    Private Sub UserForm_Initialize()
    Dim LastLig As Long
    Dim Tb
     
    With Worksheets("Repertoire")
        LastLig = .Cells(.Rows.Count, "A").End(xlUp).Row
        Tb = .Range("A3:A" & LastLig)
    End With
    TriRapide Tb, 1, LastLig - 2
    Me.ComboBox1.List = Tb
    End Sub
     
     
    Private Sub TriRapide(T As Variant, ByVal LB As Long, ByVal UB As Long)
    Dim Med As String, Hi As String, Lo As String
    Dim i As Long
     
    If LB >= UB Then Exit Sub
    i = Int((UB - LB + 1) * Rnd + LB)
    Med = T(i, 1)
    T(i, 1) = T(LB, 1)
    Lo = LB
    Hi = UB
    Do
        Do While T(Hi, 1) >= Med
            Hi = Hi - 1
            If Hi <= Lo Then Exit Do
        Loop
        If Hi <= Lo Then
            T(Lo, 1) = Med
            Exit Do
        End If
        T(Lo, 1) = T(Hi, 1)
        Lo = Lo + 1
        Do While T(Lo, 1) < Med
            Lo = Lo + 1
            If Lo >= Hi Then Exit Do
        Loop
        If Lo >= Hi Then
            Lo = Hi
            T(Hi, 1) = Med
            Exit Do
        End If
        T(Hi, 1) = T(Lo, 1)
    Loop
    TriRapide T, LB, Lo - 1
    TriRapide T, Lo + 1, UB
    End Sub

  3. #3
    Membre éclairé
    Inscrit en
    Septembre 2008
    Messages
    629
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 629
    Par défaut
    Bonjour Mercatog

    Excuse moi

    Je te remercie beaucoup mais les huit premiers nom de la combobox se mettent par ordre alpha et les autres non ?

    @+

    Max

  4. #4
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut

    Relis ce que tu viens d'écrire;. c'est tout sauf clair.

  5. #5
    Membre éclairé
    Inscrit en
    Septembre 2008
    Messages
    629
    Détails du profil
    Informations forums :
    Inscription : Septembre 2008
    Messages : 629
    Par défaut
    Bonjour Mercatog

    Excuse moi! Sur les huit premiers nom de la combobox ils se mettent par ordre alpha et les autres par ordre qu'ils se trouvent sur la feuille.

    Bonne journée

    Max

  6. #6
    Expert éminent Avatar de mercatog
    Homme Profil pro
    Inscrit en
    Juillet 2008
    Messages
    9 435
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Autre

    Informations forums :
    Inscription : Juillet 2008
    Messages : 9 435
    Par défaut
    Remplace la sub Trirapide par celle-ci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    Private Sub TriRapide(T As Variant, ByVal First As Long, ByVal Last As Long)
    Dim Low As Long, High As Long
    Dim MidValue As String, Temp As String
     
    Low = First
    High = Last
    MidValue = T((First + Last) \ 2, 1)
     
    Do
        While T(Low, 1) < MidValue
            Low = Low + 1
        Wend
     
        While T(High, 1) > MidValue
            High = High - 1
        Wend
     
        If Low <= High Then
            Temp = T(Low, 1)
            T(Low, 1) = T(High, 1)
            T(High, 1) = Temp
            Low = Low + 1
            High = High - 1
        End If
    Loop While Low <= High
     
    If First < High Then TriRapide T, First, High
    If Low < Last Then TriRapide T, Low, Last
    End Sub

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Multi-selection dans une ComboBox ?
    Par Moloko dans le forum MFC
    Réponses: 5
    Dernier message: 07/07/2021, 17h26
  2. [Débutant] ComboBox triée par catégories
    Par TheYggdrazil dans le forum C#
    Réponses: 4
    Dernier message: 26/06/2012, 16h04
  3. Tri alpha numérique des combobox
    Par fisio dans le forum VBA Access
    Réponses: 5
    Dernier message: 09/06/2009, 06h25
  4. Alpha blending
    Par Freakazoid dans le forum DirectX
    Réponses: 2
    Dernier message: 23/05/2002, 19h37
  5. Alpha blending et Z-buffer directx 8
    Par Cesar4 dans le forum DirectX
    Réponses: 1
    Dernier message: 23/05/2002, 12h58

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo