1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Public Sub Filtrage(ByVal Colonne As Integer, cible As String) 'Colonne, colonne de catégorie, cible adresse de la cellule cible
Dim Plage As Range, PlageFiltre As Range
Dim m As Double
Dim LastLig As Long
Application.ScreenUpdating = False
With Sheets("Feuil1")
LastLig = .Cells(Rows.Count, "A").End(xlUp).Row
Set Plage = .Range(.Cells(1, 1), .Cells(LastLig, Columns.Count))
Plage.AutoFilter field:=Colonne, Criteria1:=">0"
If Plage.SpecialCells(xlCellTypeVisible).Count > Columns.Count Then
Set PlageFiltre = .Range(.Cells(2, Colonne), .Cells(LastLig, Colonne)).SpecialCells(xlCellTypeVisible)
Sheets("Feuil2").Range(cible) = Application.Average(PlageFiltre)
Sheets("Feuil2").Range(cible).Offset(1, 0) = Application.Median(PlageFiltre)
Else
Sheets("Feuil2").Range(cible) = 0
Sheets("Feuil2").Range(cible).Offset(1, 0) = 0
End If
Plage.AutoFilter field:=Colonne
Set Plage = Nothing
Set PlageFiltre = Nothing
End With
End Sub |
Partager