Bonjour a tous,
J'ai chercher sur ce très bon forum ou j'ai trouver plein de choses, pour m'améliorer sur le VBA. Mais la je bloque voila j'ai une listbox sur un userform.
La listbox a droite est remplit grâce a mon textbox du milieu. Je fais une recherche sur mon fichier excel pour trouver tous les noms commençant par 10. Cela fonctionne, mais la chose que je n'arrive plus a faire ces trier ma listbox par ordre alphabétique .
voici le code que j'ai mis pour réaliser la recherche sur mon fichier ainsi que le tri par ordre alphabétique. Mais cela ne fonctionne pas. Est ce que quelqu'un peut me donner un coup de main?
PS : la textbox 7 est la case du milieu sur le userform avec le 10 a l'intérieur.
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
49
50
51
52
53
54
55
56
57
58
59
60
61 Private Sub CommandButton4_Click() 'OK Dim I As Byte For I = 1 To 5 Next I Me.TextBox7 = "" For I = 1 To 5 Me.TextBox7 = Me.TextBox7 & Me.Controls("TextBox" & I) Next I a = Me.TextBox7 Dim oCel As Range ListBox1.Clear If TextBox7.Text = "" Then TextBox7.SetFocus MsgBox "Aucun critère de recherche saisi !", vbCritical Exit Sub End If Worksheets("feuil1").Select For Each oCel In ActiveSheet.Range("I2:I" & ActiveSheet.Range("I65536").End(xlUp).Row) If oCel.Value Like TextBox7.Text & "*" Then ListBox1.AddItem oCel.Value End If Next oCel If ListBox1.ListCount = 0 Then With TextBox7 .SelStart = 0 .SelLength = Len(TextBox7.Text) .SetFocus End With MsgBox "La référence demandé n'existe pas. ", vbOKOnly Else ListBox1.ListIndex = 0 End If If ListBox1.ListIndex <> 0 Then With UserForm1.ListBox1 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 If End Sub
Merci d'avance pour vos réponse.
Partager