1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
Sub Test()
Dim Fe As Worksheet
Dim Plage As Range
Dim Tbl(1 To 3)
For Each Fe In Worksheets 'toutes les feuilles
Set Plage = DefPlage(Fe) 'appel de la fonction
'tableau de critères (fonctionne qu'à partir d'Excel 2007 !)
Tbl(1) = "A": Tbl(2) = "M": Tbl(3) = "S"
With Plage
.AutoFilter 3, Tbl, xlFilterValues 'filtre sur la colonne C (3)
Fe.AutoFilter.Range.Copy Fe.Cells(Plage.Rows.Count + 1, 1)
.AutoFilter 'supprime le filtrage
Plage.Delete 'le résultat du filtrage collé sous la plage, supprime cette dernière
End With
Next Fe
End Sub
Function DefPlage(Fe As Worksheet, Optional L As Long = 1, Optional C As Long = 1) As Range
On Error GoTo Fin
With Fe
Set DefPlage = .Range(.Cells(L, C), _
.Cells(.Cells.Find("*", .[A1], -4123, , _
1, 2).Row, .Cells.Find("*", .[A1], -4123, , _
2, 2).Column))
End With
Exit Function
Fin:
Set DefPlage = Nothing
End Function |
Partager