Bonjour à tous
Quelqu'un porrait il m'aider à faire une formule de tri soit alphamétrique ou numérique
Je désirerais trier dans une listbox les résultats de recherche d'un classeur excel
Voiçi mon code qui se trouve dans un userform
Option Explicit
Sub RechercheMot()
Dim Mot As String, Trouvé1 As Range, Trouvé2 As Range, Reponse As String
Dim i As Byte
ListBox1.Visible = False
Mot = TextBox1.Value
If Mot = "" Then
TextBox2.Value = "Veuillez entrer une valeur "
Else
TextBox2.Value = " "
For i = 1 To Sheets.Count
Sheets(i).Select: Set Trouvé1 = Cells.Find(What:=Mot)
If Not Trouvé1 Is Nothing Then
Trouvé1.Activate
With ActiveCell.Characters(Start:=InStr(1, Selection, Left(Mot, 1), 1), Length:=Len(Mot))
Selection.Interior.ColorIndex = 4 'colorie en vert
Selection.Font.Bold = True 'met en gras
ListBox1.Visible = True
ListBox1.AddItem Trouvé1
End With
étiq:
Reponse = MsgBox("Poursuivre la recherche ?", vbYesNo) 'nécessaire aussi pour stopper la recherche
If Reponse = 6 Then 'si le bouton yes est utilisé
Selection.Interior.ColorIndex = xlNone 'Couleur d'origine
Selection.Font.Bold = False 'enlever le gras
Else 'idem plus haut si le bouton non est choisi
Selection.Interior.ColorIndex = xlNone 'Couleur d'origine
Selection.Font.Bold = False
Exit Sub 'Sortie de la réponse non
End If
Set Trouvé2 = ActiveSheet.UsedRange.FindNext(After:=ActiveCell)
If Trouvé2.Address <> Trouvé1.Address Then
Trouvé2.Activate
With ActiveCell.Characters(Start:=InStr(1, Selection, Left(Mot, 1), 1), Length:=Len(Mot))
Selection.Interior.ColorIndex = 4 'colorie en vert
Selection.Font.Bold = True 'met en gras
End With
ListBox1.Visible = True
ListBox1.AddItem Trouvé2
GoTo étiq
End If
End If
Next i
Sheets(1).Activate
Range("A1").Select
End If
End Sub
Private Sub CommandButton1_Click()
RechercheMot
End Sub
Private Sub CommandButton2_Click()
ListBox1.Clear
End Sub
Private Sub CommandButton3_Click()
End
End Sub