Bonjour
je souhaiterais avoir un tri alphabétique dans un combox

j'ai ce code qui renvoi la valeur de la colonne 1 dans textbox2 et la valeur de la troisième colonne dans TxtPma

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
Private Sub ComboBox4_Change()
'Liste combo
Me.ComboBox4.List = Sheets("Villes").[A2].Resize([A1].End(xlDown).Row, 3).Value
'renvoi la valeur dans Textbox2
Me.TextBox2 = Me.ComboBox4.Value
' renvoi valeur de la colonne 3 dans TxtPma
Me.TxtPmA = Me.ComboBox4.Column(2)
 
If Me.TxtPmA = "N" Then ' Si la Valeur = N couleur fond =rouge
    Me.TxtPmA.BackColor = RGB(255, 0, 0)
    Else
    Me.TxtPmA.BackColor = RGB(255, 255, 255)
End If
Me.ComboBox5.SetFocus
End Sub
J'ai cherché quelques exemples mais je ne sais pas comment l'intégrer dans ce code.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
With Me.ComboBox4
    For i = 0 To .ListCount - 1
        For j = 0 To .ListCount - 1
            If .List(i) < .List(j) Then
                strTemp = .List(i)
                .List(i) = .List(j)
                .List(j) = strTemp
                End If
        Next j
    Next i
End With
activation userform

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
Private Sub UserForm_Activate()
 
 
Dim Cel As Range
Dim i As Byte, j As Byte
 
Set f = Sheets("villes")
   Set Rng = f.Range("A2:A" & f.[A65000].End(xlUp).Row)
For Each Cel In Rng
    Me.ComboBox4.AddItem Cel.Value
Next Cel
With Me.ComboBox4
    For i = 0 To .ListCount - 1
        For j = 0 To .ListCount - 1
            If .List(i) < .List(j) Then
                strTemp = .List(i)
                .List(i) = .List(j)
                .List(j) = strTemp
                End If
        Next j
    Next i
End With
 
End Sub
Merci