R
romain
Guest
j'ai besoin d'un petit coup de main. je tente de créer une sorte de macro "moteur de recherche" déclenchant une recherche sur toutes les feuilles. mais je ne maitrise pas tres bien VBA... si quelqu'un peut m'aider...
merci.
voici la macro :
Private Sub CommandButton2_Click()
mot = InputBox("Mot à rechercher ? (mot simple ou suite logique)")
If mot = "" Then Exit Sub
For feuille = 1 To Sheets.Count
Sheets(feuille).Select
Set trouvé1 = Cells.Find(What:=mot)
If Not trouvé1 Is Nothing Then
With trouvé1
.Activate
.Select
.Font.ColorIndex = 3
End With
étiq:
If MsgBox("Suivant ?", 4) = vbNo Then Exit Sub
Set trouvé2 = Cells.FindNext(After:=ActiveCell)
Set trouvé3 = Cells.FindPrevious(After:=ActiveCell)
Do While trouvé2 <> trouvé1
With trouvé1
.Select
.Font.ColorIndex = 0
End With
With trouvé3
.Select
.Font.ColorIndex = 0
End With
With trouvé2
.Activate
.Select
.Font.ColorIndex = 3
End With
GoTo étiq
Loop
End If
Next feuille
MsgBox "Rien trouvé"
End Sub
merci.
voici la macro :
Private Sub CommandButton2_Click()
mot = InputBox("Mot à rechercher ? (mot simple ou suite logique)")
If mot = "" Then Exit Sub
For feuille = 1 To Sheets.Count
Sheets(feuille).Select
Set trouvé1 = Cells.Find(What:=mot)
If Not trouvé1 Is Nothing Then
With trouvé1
.Activate
.Select
.Font.ColorIndex = 3
End With
étiq:
If MsgBox("Suivant ?", 4) = vbNo Then Exit Sub
Set trouvé2 = Cells.FindNext(After:=ActiveCell)
Set trouvé3 = Cells.FindPrevious(After:=ActiveCell)
Do While trouvé2 <> trouvé1
With trouvé1
.Select
.Font.ColorIndex = 0
End With
With trouvé3
.Select
.Font.ColorIndex = 0
End With
With trouvé2
.Activate
.Select
.Font.ColorIndex = 3
End With
GoTo étiq
Loop
End If
Next feuille
MsgBox "Rien trouvé"
End Sub