Sub recherche_pdvratt()
Application.ScreenUpdating = False
Dim twb As Workbook
Set twb = ThisWorkbook
Dim WbData As Workbook
Dim resultat As String
Dim tablo() As Variant
'on efface la feuille de résultat
Sheets("Import_HISTO(PDVratt)").Range("A1").CurrentRegion.Offset(1, 0).ClearContents
'on récumère le numéro du magasin"
MagasinNb = twb.Sheets("Menu").Range("C26")
MsgBox "La recherche va s'effectuer sur le magasin rattaché n°" & MagasinNb
' on va parcourir un à un toutes les feuilles du classeur en cours, ws identifie chacune de ces feuilles
'Ouverture du fichier pour la recherche
Workbooks.Open Filename:="\\chemindufichierexcel.xlsx"
Set WbData = ActiveWorkbook
With WbData
For Each ws In .Sheets
If ws.Name Like "B*" Then 'condition pour ne travailler que les feuilles Bxxxx
'MsgBox ws.Name
tablo = ws.Range("A1").CurrentRegion.Value 'on place toute la feuille dans un tablo
For i = 1 To UBound(tablo, 1)
If UCase(tablo(i, 2)) <> UCase(MagasinNb) Then 'si c'est pas le bon magasin, on vide la ligne du tablo
For j = 1 To UBound(tablo, 2)
tablo(i, j) = ""
Next j
End If
Next i
With twb.Sheets("Import_HISTO(PDVratt)") 'on recopie le tablo en fin de feuille
fin = .Range("A" & .Rows.Count).End(xlUp).Row + 1
.Range("A" & fin).Resize(UBound(tablo, 1), UBound(tablo, 2)) = tablo
.Range("A" & fin).Resize(UBound(tablo, 1), 1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete 'et on supprime les lignes vides
End With
End If
Next ws
End With
' Windows("HistoData.xlsx").Activate 'fichier ouvert plus haut pour faire l'extraction des données chemindufichierexcel'
' Application.CutCopyMode = False
' ActiveWindow.Close
'
'
' Sheets("Import_HISTO(PDVratt)").Select
Application.ScreenUpdating = True
End Sub