Simplification code pour filtre/statiqtiques

maninwhite

XLDnaute Occasionnel
Bonjour à toutes et à tous

Afin de réaliser des statistiques et plutôt que de faire manuellement des calculs, j'utilise un code qui me filtre des colonnes sur 1, 2 voir 3 critères, qui me compte le nombre de fois ou certains mots apparaissent et qui me reporte ce nombre dans un tableau.

Le soucis c'est que mon code est immense et je pense qu'il peut sans aucun doute être simplifié.

Ci dessous un exemple :

Code:
'Critère 1
Worksheets("report").Range("A:A").AutoFilter Field:=5, Criteria1:= _
        "Critère 1)"
        
'Mars
Worksheets("report").Range("A:A").AutoFilter Field:=8, Criteria1:= _
        xlFilterAllDatesInPeriodMarch, Operator:=xlFilterDynamic
        
'Usine
Worksheets("Statistiques FY 1314").Range("AL15").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test1")
Worksheets("Statistiques FY 1314").Range("AM15").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test2")
Worksheets("Statistiques FY 1314").Range("AN15").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test3")

'Département1
Worksheets("report").Range("A:A").AutoFilter Field:=11, Criteria1:= _
        "Département1"
Worksheets("Statistiques FY 1314").Range("AL16").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test1")
Worksheets("Statistiques FY 1314").Range("AM16").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test2")
Worksheets("Statistiques FY 1314").Range("AN16").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test3")

'Département2
Worksheets("report").Range("A:A").AutoFilter Field:=11, Criteria1:= _
        "Département2"
Worksheets("Statistiques FY 1314").Range("AL17").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test1")
Worksheets("Statistiques FY 1314").Range("AM17").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test2")
Worksheets("Statistiques FY 1314").Range("AN17").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test3")

'Département3
Worksheets("report").Range("A:A").AutoFilter Field:=11, Criteria1:= _
        "Département3"
Worksheets("Statistiques FY 1314").Range("AL18").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test1")
Worksheets("Statistiques FY 1314").Range("AM18").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test2")
Worksheets("Statistiques FY 1314").Range("AN18").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test3")

Département4
Worksheets("report").Range("A:A").AutoFilter Field:=11, Criteria1:= _
        "Département4"
Worksheets("Statistiques FY 1314").Range("AL19").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test1")
Worksheets("Statistiques FY 1314").Range("AM19").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test2")
Worksheets("Statistiques FY 1314").Range("AN19").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test3")

Département5
Worksheets("report").Range("A:A").AutoFilter Field:=11, Criteria1:= _
        "Département5"
Worksheets("Statistiques FY 1314").Range("AL20").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test1")
Worksheets("Statistiques FY 1314").Range("AM20").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test2")
Worksheets("Statistiques FY 1314").Range("AN20").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test3")

'Département6
Worksheets("report").Range("A:A").AutoFilter Field:=11, Criteria1:= _
        "Département6"
Worksheets("Statistiques FY 1314").Range("AL21").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test1")
Worksheets("Statistiques FY 1314").Range("AM21").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test2")
Worksheets("Statistiques FY 1314").Range("AN21").Value = NBSIVisibles(Worksheets("report").Range("J3:J1000"), "Test3")

'Réinitialiser les filtres
Worksheets("report").Range("A:A").AutoFilter Field:=5
Worksheets("report").Range("A:A").AutoFilter Field:=8
Worksheets("report").Range("A:A").AutoFilter Field:=11

Pour résumer je filtre sur le critère 1, puis sur le mois, puis par département et je dois répéter ce code 12 fois vu que je veux mes résultats pour chaque mois.

Malheureusement je ne peux pas mettre le fichier en PJ car il y a des infos sensibles dedans.

Merci
 

Misange

XLDnaute Barbatruc
Re : Simplification code pour filtre/statiqtiques

Bonjour
Tu te doutes bien que si personne ne peut voir le contenu (anonymisé !) du classeur tu auras peu d'aide.
En ce qui me concerne quand je lis la description de ce que tu fais je réponds : tableau croisé dynamique immédiatement, c'est fait justement pour ça.
Ce lien n'existe plus
Filtrer sur de multiples critères, faire des sommes de moyennes des écartypes suivant ces critères et générer les graphiques associés sans entrer une ligne de code ou une seule formule, le tout avec la rapidité du langage machine... c'est dommage de s'en priver.
 

Discussions similaires