Bonjour,

Voila j'ai un soucis sur ce 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
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
Dim j As Byte
Dim k 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
 
 
        With UserForm1.ListBox1
          For k = 0 To .ListCount - 1
            For j = 0 To .ListCount - 1
               If .List(k) < .List(j) Then
                    strTemp = .List(k)
                    .List(k) = .List(j)
                    .List(j) = strTemp
                End If
            Next j
        Next k
    End With
 
 
End Sub
lorsque je ne trouve pas de résultat il essaye de faire le tri, et du coup il me renvoi une erreur. Comment faire pour ne plus avoir cette erreur ?

Ensuite j'ai une deuxième question, à la suite de ma recherche, a partir d'une valeur sélectionner dans ma listbox je voudrais que ca mette en surbrillance ma ligne sur mon tableur. Je ne sais pas si je me fais bien comprendre.


Si besoin de compléments n'hésitez pas a demander.