How to reduce a repetitive macro (loop maybe?)

Blanchetdb

Board Regular
Joined
Jul 31, 2018
Messages
161
Office Version
  1. 2016
Platform
  1. Windows
Hi

So, I have a macro that is repetitive with the only change is the name being searched. The macro works but I am limited on the number of names because I get an error message saying it is too large. Can someone help on condensing this maybe in a loop (not sure how to do that)

VBA Code:
Private Sub CommandButton1_Click()
Range("F15") = Range("D5")

If Range("D5") <> "" Then
Range("P17:P2000").AutoFilter Field:=1, Criteria1:=Range("D5").Value
End If
 
'All / TOUS
If Range("D5") = "" And Range("AB9") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("AD18:AD2000"), "0")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("AD18:AD2000"), "0")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("AD18:AD2000"), "0")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "0")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("AD18:AD2000"), "0")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("AD18:AD2000"), "0")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("AD18:AD2000"), "0")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("AD18:AD2000"), "0")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("AD18:AD2000"), "0")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("AD18:AD2000"), "0")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("AD18:AD2000"), "0")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("AD18:AD2000"), "0")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("AD18:AD2000"), "0")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "0")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("AD18:AD2000"), "0")
End If
If Range("D5") = "" And Range("AB10") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("AD18:AD2000"), "1")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("AD18:AD2000"), "1")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("AD18:AD2000"), "1")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "1")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("AD18:AD2000"), "1")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("AD18:AD2000"), "1")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("AD18:AD2000"), "1")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("AD18:AD2000"), "1")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("AD18:AD2000"), "1")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("AD18:AD2000"), "1")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("AD18:AD2000"), "1")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("AD18:AD2000"), "1")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("AD18:AD2000"), "1")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "1")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("AD18:AD2000"), "1")
End If
If Range("D5") = "" And Range("AB11") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("AD18:AD2000"), "2")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("AD18:AD2000"), "2")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("AD18:AD2000"), "2")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "2")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("AD18:AD2000"), "2")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("AD18:AD2000"), "2")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("AD18:AD2000"), "2")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("AD18:AD2000"), "2")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("AD18:AD2000"), "2")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("AD18:AD2000"), "2")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("AD18:AD2000"), "2")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("AD18:AD2000"), "2")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("AD18:AD2000"), "2")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "2")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("AD18:AD2000"), "2")
End If
If Range("D5") = "" And Range("AB12") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("AD18:AD2000"), "3")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("AD18:AD2000"), "3")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("AD18:AD2000"), "3")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "3")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("AD18:AD2000"), "3")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("AD18:AD2000"), "3")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "3")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "3")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "3")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("AD18:AD2000"), "3")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("AD18:AD2000"), "3")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("AD18:AD2000"), "3")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("AD18:AD2000"), "3")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("AD18:AD2000"), "3")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("AD18:AD2000"), "3")
End If

'Jarek Krukowski
If Range("D5") = "Jarek Krukowski" And Range("AB9") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "0")
End If
If Range("D5") = "Jarek Krukowski" And Range("AB10") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "1")
End If
If Range("D5") = "Jarek Krukowski" And Range("AB11") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "2")
End If
If Range("D5") = "Jarek Krukowski" And Range("AB12") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Jarek Krukowski", Range("AD18:AD2000"), "3")
End If


'Genève Fournier
If Range("D5") = "Genève Fournier" And Range("AB9") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "0")
End If
If Range("D5") = "Genève Fournier" And Range("AB10") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "1")
End If
If Range("D5") = "Genève Fournier" And Range("AB11") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "2")
End If
If Range("D5") = "Genève Fournier" And Range("AB12") = True Then
Range("I9") = WorksheetFunction.CountIfs(Range("X18:X2000"), "In Progress / Encours", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("I10") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed / Finalisé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("I11") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Ongoing / Finalisé - continu", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("I12") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Completed - Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("I13") = WorksheetFunction.CountIfs(Range("X18:X2000"), "Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")

Range("D9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "01 Planning Phase / Phase de planification", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("D10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "02 Poster Open / Affiche ouverte", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("D11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "03 Screening Phase / Phase de dépistage", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("D12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "04 Assessment Phase / Phase d'évaluation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("D13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "05 Process Being Finalized / Processus en cours de finalisation", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("G9") = WorksheetFunction.CountIfs(Range("T18:T2000"), "06 Process completed, Pool Created / Processus complété; bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("G10") = WorksheetFunction.CountIfs(Range("T18:T2000"), "07 Process completed, No Pool Created / Processus complété; sans bassin créé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("G11") = WorksheetFunction.CountIfs(Range("T18:T2000"), "08 Cancelled / Annulé", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("G12") = WorksheetFunction.CountIfs(Range("T18:T2000"), "09 Unproductive / Finalisé - improductif", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
Range("G13") = WorksheetFunction.CountIfs(Range("T18:T2000"), "10 Other - See Comments / Autres - Voir commentaires", Range("P18:P2000"), "Genève Fournier", Range("AD18:AD2000"), "3")
End If

this macro repeats for another 3 names but then I am unable to add additional names

can someone please provide a solution on how to reduce this?

thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
It would be helpful if you could provide a copy of your sheet using the XL2BB add in, or alternatively share your file via Google Drive, Dropbox or similar file sharing platform. Having said that, please try the following when you get the chance on a copy of your workbook (change the sheet name in the code to match your actual sheet name). I won't be able to get back to you tonight, but I will get back to you when I can.
VBA Code:
Option Explicit
Sub CommandButton1_Click()
    Dim ws As Worksheet, s As String
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ***
    If ws.AutoFilterMode Then ws.AutoFilter.ShowAllData
    s = ws.Range("D5")
    ws.Range("F15") = s
   
    Dim j As Long, k As Long, m As Long, n As Long
    Dim p, t, x, ab, ad, nums, cats
    nums = Array("01 ", "02 ", "03 ", "04 ", "05 ", "06 ", "07 ", "08 ", "09 ", "10 ")
    cats = Array("*Encours*", "*Completed /*", "*continu*", "*Unproductive*", "*Annulé*")
    p = ws.Range("P18:P2000")
    t = ws.Range("T18:T2000")
    x = ws.Range("X18:X2000")
    ab = ws.Range("AB9:AB12")
    ad = ws.Range("AD18:AD2000")
    n = Application.Match(True, ab, 0) - 1
    ReDim results(1 To 5, 1 To 1)
   
    If s = "" Then
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j - 1) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j - 1) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j + 4) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
    Else
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j + 4) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j + 4) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
            If t(k, 1) Like nums(j + 4) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
                Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
    End If
End Sub
 
Upvote 0
You could try this with worksheet formulas rather than VBA. You will have to update ranges to match your data and write similar formulas for the other COUNTIFS.
Book1
DEFGHIJKLMNOPQRSTUVWXYZAAABACAD
13
2
3
4
5Jarek
6
7
8
9001 Planning Phase / Phase de planificationFALSE
10102 Poster Open / Affiche ouverteFALSE
11003 Screening Phase / Phase de dépistageFALSE
12104 Assessment Phase / Phase d'évaluationTRUE
13005 Process Being Finalized / Processus en cours de finalisation
14106 Process completed, Pool Created / Processus complété; bassin créé
15107 Process completed, No Pool Created / Processus complété; sans bassin créé
16208 Cancelled / Annulé
17109 Unproductive / Finalisé - improductif
18110 Other - See Comments / Autres - Voir commentairesBob10 Other - See Comments / Autres - Voir commentaires2
19Bob08 Cancelled / Annulé3
20Mike07 Process completed, No Pool Created / Processus complété; sans bassin créé2
21Jarek03 Screening Phase / Phase de dépistage2
22Jarek07 Process completed, No Pool Created / Processus complété; sans bassin créé3
23Jarek09 Unproductive / Finalisé - improductif3
24Mike08 Cancelled / Annulé3
25Bob06 Process completed, Pool Created / Processus complété; bassin créé3
26Genève04 Assessment Phase / Phase d'évaluation2
27Genève08 Cancelled / Annulé2
28Genève08 Cancelled / Annulé2
29Jarek01 Planning Phase / Phase de planification2
30Genève05 Process Being Finalized / Processus en cours de finalisation2
31Genève04 Assessment Phase / Phase d'évaluation3
32Mike05 Process Being Finalized / Processus en cours de finalisation2
33Mike07 Process completed, No Pool Created / Processus complété; sans bassin créé2
34Bob10 Other - See Comments / Autres - Voir commentaires2
35Jarek04 Assessment Phase / Phase d'évaluation3
36Jarek08 Cancelled / Annulé3
37Bob01 Planning Phase / Phase de planification3
38Bob07 Process completed, No Pool Created / Processus complété; sans bassin créé2
39Mike08 Cancelled / Annulé2
40Mike07 Process completed, No Pool Created / Processus complété; sans bassin créé3
41Genève06 Process completed, Pool Created / Processus complété; bassin créé3
42Bob09 Unproductive / Finalisé - improductif2
43Bob07 Process completed, No Pool Created / Processus complété; sans bassin créé3
44Genève06 Process completed, Pool Created / Processus complété; bassin créé2
45Bob01 Planning Phase / Phase de planification3
46Bob10 Other - See Comments / Autres - Voir commentaires3
47Mike02 Poster Open / Affiche ouverte2
48Mike05 Process Being Finalized / Processus en cours de finalisation3
49Mike01 Planning Phase / Phase de planification2
50Jarek06 Process completed, Pool Created / Processus complété; bassin créé3
51Bob07 Process completed, No Pool Created / Processus complété; sans bassin créé2
52Mike02 Poster Open / Affiche ouverte2
53Bob08 Cancelled / Annulé2
54Jarek05 Process Being Finalized / Processus en cours de finalisation2
55Jarek02 Poster Open / Affiche ouverte3
56Genève08 Cancelled / Annulé3
57Mike03 Screening Phase / Phase de dépistage2
58Bob05 Process Being Finalized / Processus en cours de finalisation3
59Bob05 Process Being Finalized / Processus en cours de finalisation2
60Genève09 Unproductive / Finalisé - improductif2
61Genève09 Unproductive / Finalisé - improductif2
62Mike09 Unproductive / Finalisé - improductif3
63Bob01 Planning Phase / Phase de planification3
64Mike09 Unproductive / Finalisé - improductif2
65Bob01 Planning Phase / Phase de planification3
66Bob02 Poster Open / Affiche ouverte3
67Bob08 Cancelled / Annulé2
68Genève09 Unproductive / Finalisé - improductif3
69Jarek08 Cancelled / Annulé3
70Jarek10 Other - See Comments / Autres - Voir commentaires3
71Genève07 Process completed, No Pool Created / Processus complété; sans bassin créé2
72Bob04 Assessment Phase / Phase d'évaluation3
73Genève08 Cancelled / Annulé3
74Genève01 Planning Phase / Phase de planification2
75Genève04 Assessment Phase / Phase d'évaluation3
76Mike07 Process completed, No Pool Created / Processus complété; sans bassin créé3
77Bob08 Cancelled / Annulé3
78Genève04 Assessment Phase / Phase d'évaluation3
Sheet1
Cell Formulas
RangeFormula
AB1AB1=IF(AB9,0,IF(AB10,1,IF(AB11,2,3)))
D9:D18D9=COUNTIFS($T$18:$T$2000,$E9,$P$18:$P$2000,IF($D$5="","*",$D$5),$AD$18:$AD$2000,$AB$1)

It should handle more names without a problem.

Hope that helps,

Doug
 
Last edited:
Upvote 0
It would be helpful if you could provide a copy of your sheet using the XL2BB add in, or alternatively share your file via Google Drive, Dropbox or similar file sharing platform. Having said that, please try the following when you get the chance on a copy of your workbook (change the sheet name in the code to match your actual sheet name). I won't be able to get back to you tonight, but I will get back to you when I can.
VBA Code:
Option Explicit
Sub CommandButton1_Click()
    Dim ws As Worksheet, s As String
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ***
    If ws.AutoFilterMode Then ws.AutoFilter.ShowAllData
    s = ws.Range("D5")
    ws.Range("F15") = s
  
    Dim j As Long, k As Long, m As Long, n As Long
    Dim p, t, x, ab, ad, nums, cats
    nums = Array("01 ", "02 ", "03 ", "04 ", "05 ", "06 ", "07 ", "08 ", "09 ", "10 ")
    cats = Array("*Encours*", "*Completed /*", "*continu*", "*Unproductive*", "*Annulé*")
    p = ws.Range("P18:P2000")
    t = ws.Range("T18:T2000")
    x = ws.Range("X18:X2000")
    ab = ws.Range("AB9:AB12")
    ad = ws.Range("AD18:AD2000")
    n = Application.Match(True, ab, 0) - 1
    ReDim results(1 To 5, 1 To 1)
  
    If s = "" Then
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j - 1) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j - 1) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j + 4) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
    Else
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j + 4) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j + 4) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
            If t(k, 1) Like nums(j + 4) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
                Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
    End If
End Sub

let me know if this works for you .... I really appreciate your time on this

also, I did try the code but it didn't work
 
Upvote 0

let me know if this works for you .... I really appreciate your time on this

also, I did try the code but it didn't work
this is the error I get:

1696123182909.png

1696123222269.png
 
Upvote 0
You need to make the shared file available to anyone with the link.
Also, try changing the name of the sub to Sub Test() and see if that works.
 
Upvote 0
Apologies for my last post that had incorrect code, as I said I was tired, I see now how it was jacked up. :(

I will wait for some sample code, with before & after results, before I make another try.
 
Upvote 0
OK, I've thrown together a test sheet that I believe your data may look like (link attached below). I've amended the code and tested it - it seems to me to give you what you want? Let me know how you go with it.
VBA Code:
Option Explicit
Sub Blanchtdb()
    Dim ws As Worksheet, s As String
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ***
    If ws.AutoFilterMode Then ws.AutoFilter.ShowAllData
    s = ws.Range("D5")
    ws.Range("F15") = s
    
    Dim j As Long, k As Long, m As Long, n As Long
    Dim p, t, x, ab, ad, nums, cats
    nums = Array("01 ", "02 ", "03 ", "04 ", "05 ", "06 ", "07 ", "08 ", "09 ", "10 ")
    cats = Array("*Encours*", "*Completed /*", "*continu*", "*Unproductive*", "*Annulé*")
    p = ws.Range("P18:P2000")
    t = ws.Range("T18:T2000")
    x = ws.Range("X18:X2000")
    ab = ws.Range("AB9:AB12")
    ad = ws.Range("AD18:AD2000")
    n = Application.Match(True, ab, 0) - 1
    ReDim results(1 To 5, 1 To 1)
    
    If s = "" Then
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j - 1) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j - 1) & "*" And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j + 4) & "*" And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
    Else
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j - 1) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j - 1) & "*" And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
            If t(k, 1) Like nums(j + 4) & "*" And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
                Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
    End If
End Sub

Link to test file
Blanchetdb.xlsm
 
Upvote 0
OK, I've thrown together a test sheet that I believe your data may look like (link attached below). I've amended the code and tested it - it seems to me to give you what you want? Let me know how you go with it.
VBA Code:
Option Explicit
Sub Blanchtdb()
    Dim ws As Worksheet, s As String
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ***
    If ws.AutoFilterMode Then ws.AutoFilter.ShowAllData
    s = ws.Range("D5")
    ws.Range("F15") = s
   
    Dim j As Long, k As Long, m As Long, n As Long
    Dim p, t, x, ab, ad, nums, cats
    nums = Array("01 ", "02 ", "03 ", "04 ", "05 ", "06 ", "07 ", "08 ", "09 ", "10 ")
    cats = Array("*Encours*", "*Completed /*", "*continu*", "*Unproductive*", "*Annulé*")
    p = ws.Range("P18:P2000")
    t = ws.Range("T18:T2000")
    x = ws.Range("X18:X2000")
    ab = ws.Range("AB9:AB12")
    ad = ws.Range("AD18:AD2000")
    n = Application.Match(True, ab, 0) - 1
    ReDim results(1 To 5, 1 To 1)
   
    If s = "" Then
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j - 1) And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j - 1) & "*" And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j + 4) & "*" And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
    Else
        For j = 1 To 5
            For k = 1 To UBound(x, 1)
                If x(k, 1) Like cats(j - 1) And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("I9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
                If t(k, 1) Like nums(j - 1) & "*" And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
            Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("D9").Resize(5, 1).Value = results
        ReDim results(1 To 5, 1 To 1)
        For j = 1 To 5
            For k = 1 To UBound(t, 1)
            If t(k, 1) Like nums(j + 4) & "*" And p(k, 1) = s And ad(k, 1) = n Then m = m + 1
                Next k
            results(j, 1) = m: m = 0
        Next j
        ws.Range("G9").Resize(5, 1).Value = results
    End If
End Sub

Link to test file
Blanchetdb.xlsm
I gave the required access.

and I tried what you recently sent me, and it gives me the same error message.
 
Upvote 0
Have you tried putting the COUNTIFS formulas on the worksheet?

Doug
 
Upvote 0

Forum statistics

Threads
1,223,937
Messages
6,175,525
Members
452,651
Latest member
wordsearch

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top