Autres filtrer les données avec deux critères en vba

hamid43

XLDnaute Nouveau
Bonjour tout le monde ! J'ai besoins votre aide svp !! comment modifier le code macro copy_filtre pour faire filtrage a deux critères cellule L2 et M2
 

Pièces jointes

  • copy_filtre.xlsm
    448.4 KB · Affichages: 1
Solution
Bonjour le Fil ;
avec un truc comme ça
VB:
Sub copy_filtre()
Application.ScreenUpdating = False
Dim sh1, sh2
Dim LastRw&
Set Sh = Sheets("Synt")

Sheets("Synt").Select
Range("A2:I" & Rows.Count).ClearContents
LastRw = Sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
crit = Sh.Range("L2")
crit2 = Sh.Range("M2")  'Ajout Ici
For i = 1 To 2
With Sheets("Ra" & i).Range("A1")
    If Not Sheets("Ra" & i).FilterMode Then
      .AutoFilter
    End If
   
    .AutoFilter Field:=1, Criteria1:="=" & crit
    .AutoFilter Field:=3, Criteria1:="=" & crit2 'Ajout Ici
 
    .Range("_FilterDatabase").Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
     Sh.Range("A" & LastRw).PasteSpecial xlPasteValues
     LastRw = Sh.Cells(Rows.Count, 1).End(xlUp).Row + 1...

ChTi160

XLDnaute Barbatruc
Bonjour le Fil ;
avec un truc comme ça
VB:
Sub copy_filtre()
Application.ScreenUpdating = False
Dim sh1, sh2
Dim LastRw&
Set Sh = Sheets("Synt")

Sheets("Synt").Select
Range("A2:I" & Rows.Count).ClearContents
LastRw = Sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
crit = Sh.Range("L2")
crit2 = Sh.Range("M2")  'Ajout Ici
For i = 1 To 2
With Sheets("Ra" & i).Range("A1")
    If Not Sheets("Ra" & i).FilterMode Then
      .AutoFilter
    End If
   
    .AutoFilter Field:=1, Criteria1:="=" & crit
    .AutoFilter Field:=3, Criteria1:="=" & crit2 'Ajout Ici
 
    .Range("_FilterDatabase").Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
     Sh.Range("A" & LastRw).PasteSpecial xlPasteValues
     LastRw = Sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
    .AutoFilter
End With
Next
    Range("A1").Select
End Sub
Jean marie
 
Dernière édition:

hamid43

XLDnaute Nouveau
Bonjour le Fil ;
avec un truc comme ça
VB:
Sub copy_filtre()
Application.ScreenUpdating = False
Dim sh1, sh2
Dim LastRw&
Set Sh = Sheets("Synt")

Sheets("Synt").Select
Range("A2:I" & Rows.Count).ClearContents
LastRw = Sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
crit = Sh.Range("L2")
crit2 = Sh.Range("M2")  'Ajout Ici
For i = 1 To 2
With Sheets("Ra" & i).Range("A1")
    If Not Sheets("Ra" & i).FilterMode Then
      .AutoFilter
    End If
  
    .AutoFilter Field:=1, Criteria1:="=" & crit
    .AutoFilter Field:=3, Criteria1:="=" & crit2 'Ajout Ici
 
    .Range("_FilterDatabase").Offset(1, 0).SpecialCells(xlCellTypeVisible).Copy
     Sh.Range("A" & LastRw).PasteSpecial xlPasteValues
     LastRw = Sh.Cells(Rows.Count, 1).End(xlUp).Row + 1
    .AutoFilter
End With
Next
    Range("A1").Select
End Sub
Jean marie
Merci beaucoup !
Ca fonctionne
 

Discussions similaires

Réponses
9
Affichages
656

Statistiques des forums

Discussions
312 229
Messages
2 086 423
Membres
103 206
dernier inscrit
diambote