Bonjour
gloub a écrit :
J'ajoute un truc auquel je n'avais pas pensé au début : si possible, j'aimerais que la recherche puisse marcher même si le nom est incomplet :
par exemple, pouvoir taper Desm pour trouver Desmares.
J'ai bien conscience que si plusieurs noms comprennent la même chaîne, ça va poser problème, mais ce n'est pas bien grave.
La macro elle fait ça : Mais pour moi il fallait que le texte recherché commence par ....
Alors dans la macro supprimes les lignes surlignées
Option Explicit
Sub Recherche()
Dim Quoi As String, Depart As String
Dim Cel As Range
Dim Ligne As Long, LigneAncienne As Long
Quoi = InputBox("Recherche")
If Quoi = "" Then Exit Sub
Set Cel = Cells.Find(what:=Quoi, LookIn:=xlFormulas, lookat:=xlPart)
If Not Cel Is Nothing Then
Depart = Cel.Address
Do
'If InStr(1, Cel, Quoi, vbTextCompare) = 1 Then
If LigneAncienne > 0 Then
On Error Resume Next
ActiveSheet.Rows(LigneAncienne).ShowDetail = False
On Error GoTo 0
End If
Ligne = Cel.Row
Do While ActiveSheet.Rows(Ligne).OutlineLevel > 1
Ligne = Ligne - 1
Loop
On Error Resume Next
ActiveSheet.Rows(Ligne).ShowDetail = True
On Error GoTo 0
Cel.Select
If MsgBox("Recherche suivante ?", vbQuestion + vbYesNo + vbDefaultButton1, "Continuer") <> vbYes Then Exit Sub
LigneAncienne = Ligne
'End If
Set Cel = Cells.FindNext(Cel)
Loop While Depart <> Cel.Address
Else
MsgBox "Introuvable : " & Quoi
End If
End Sub
Edit : Bonsoir vba-new
vba-new a écrit :
Bonsoir à tous !
Banzai, un petit oubli dans le code :
If InStr(1, Cel, Quoi, vbTextCompare) >= 1 Then
Hé non ce n'est pas un oubli, juste une restriction