Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 20/11/2011, 15h33   #1
Invité de passage
 
Inscription : septembre 2008
Messages : 121
Détails du profil
Informations forums :
Inscription : septembre 2008
Messages : 121
Points : 4
Points : 4
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 :
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
apdf1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/11/2011, 15h47   #2
Expert Confirmé Sénior
 
Avatar de mercatog
 
Inscription : juillet 2008
Messages : 5 848
Détails du profil
Informations forums :
Inscription : juillet 2008
Messages : 5 848
Points : 13 907
Points : 13 907
En utilisant l'algorithme de tri rapide QuickSort
Code :
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
__________________
Cordialement.
mercatog est déconnecté   Envoyer un message privé Réponse avec citation 20
Vieux 20/11/2011, 16h00   #3
Invité de passage
 
Inscription : septembre 2008
Messages : 121
Détails du profil
Informations forums :
Inscription : septembre 2008
Messages : 121
Points : 4
Points : 4
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
apdf1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 20/11/2011, 16h05   #4
Expert Confirmé Sénior
 
Avatar de mercatog
 
Inscription : juillet 2008
Messages : 5 848
Détails du profil
Informations forums :
Inscription : juillet 2008
Messages : 5 848
Points : 13 907
Points : 13 907

Relis ce que tu viens d'écrire;. c'est tout sauf clair.
__________________
Cordialement.
mercatog est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 21/11/2011, 09h57   #5
Invité de passage
 
Inscription : septembre 2008
Messages : 121
Détails du profil
Informations forums :
Inscription : septembre 2008
Messages : 121
Points : 4
Points : 4
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
apdf1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/11/2011, 11h46   #6
Expert Confirmé Sénior
 
Avatar de mercatog
 
Inscription : juillet 2008
Messages : 5 848
Détails du profil
Informations forums :
Inscription : juillet 2008
Messages : 5 848
Points : 13 907
Points : 13 907
Remplace la sub Trirapide par celle-ci
Code :
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
__________________
Cordialement.
mercatog est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/11/2011, 17h10   #7
Invité de passage
 
Inscription : septembre 2008
Messages : 121
Détails du profil
Informations forums :
Inscription : septembre 2008
Messages : 121
Points : 4
Points : 4
Bonjour Mercatog

Je te remercie beaucoup sa marche Nickel

Je te souhaite une bonne soirée

Max
apdf1 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 08h34.


 
 
 
 
Partenaires

Hébergement Web