Sub Recherche_CodeAnalytique()
'
Dim ws As Worksheet, wsResultat As Worksheet
Dim CodeRecherche As String
Dim LigneResultat As Long, i As Long
Dim Feuilles()
'--- Demande le code analytique à rechercher
CodeRecherche = InputBox("Entrez le code analytique à rechercher :", "Filtre Analytique")
If CodeRecherche = "" Then Exit Sub
Application.ScreenUpdating = False
'--- Feuilles à parcourir
Feuilles = Array("Vente", "Achat", "Déplacement2", "Pointage")
'--- Crée ou vide la feuille Résultat
On Error Resume Next
Set wsResultat = ThisWorkbook.Worksheets("Résultat")
If wsResultat Is Nothing Then
Set wsResultat = ThisWorkbook.Worksheets.Add
wsResultat.Name = "Résultat"
Else
wsResultat.Cells.Clear
End If
On Error GoTo 0
wsResultat.Cells(1, 1).Value = "Feuille Source"
LigneResultat = 2
'--- Parcours des feuilles listées
For i = LBound(Feuilles) To UBound(Feuilles)
Set ws = ThisWorkbook.Sheets(Feuilles(i))
With Range("t_" & Feuilles(i))
.AutoFilter Field:=1, Criteria1:=CodeRecherche
On Error Resume Next
a = 0
a = .SpecialCells(xlCellTypeVisible).Rows.Count
If a <> 0 Then
.Copy Destination:=wsResultat.Cells(LigneResultat, 1)
End If
On Error GoTo 0
.AutoFilter Field:=1
End With
LigneResultat = wsResultat.Cells(ws.Rows.Count, 1).End(xlUp).Row + 1
Next i
Application.ScreenUpdating = True
MsgBox LigneResultat - 2 & " lignes trouvées pour le code " & CodeRecherche, vbInformation, "Recherche terminée"
End Sub