XL 2016 formule matricielle

SPARKLETOF

XLDnaute Junior
Bonjour,

j'ai un fichier excel dans lequel se trouve des infos concernant l'année, n° de dossier, n° échantillons et type d'analyses.
Je cherche un moyen d'obtenir le nombre de dossiers par type d'analyses et par année....
J'ai une formule en matricielle qui me sert compter le nombre de dossiers différents pour une année mais en ajoutant ces conditions je suis perdu...
Quelqu'un peut m'aider ?
Je joins le fichier (un exemple, car le miens possède environ 20000 lignes...)
Merci par avance.
Pour info je suis avec Excel 2016
SKF
 

Pièces jointes

  • Dossiers analyses.xlsx
    10.1 KB · Affichages: 26

vgendron

XLDnaute Barbatruc
Hello
un essai par macro
VB:
Sub Compter()

Dim tablo() As Variant
Set dico = CreateObject("Scripting.dictionary")

With Sheets("Feuil2")
    Fin = .UsedRange.Rows.Count
    tablo = .Range("A2:D" & Fin).Value
End With

For i = LBound(tablo, 1) To UBound(tablo, 1)
    If Not dico.exists(tablo(i, 2) & "-" & tablo(i, 1)) Then
        dico.Add tablo(i, 2) & "-" & tablo(i, 1), tablo(i, 4)
    End If
   
Next i

'Recherche 1==>Eau - 2013
TypeSol = "eau"
annee = 2013
Rech = 0
For Each ele In dico.keys
    If CInt(Split(ele, "-")(1)) = annee And UCase(dico.Item(ele)) = UCase(TypeSol) Then
        Rech = Rech + 1
    End If
Next ele
Range("G3") = Rech

'Recherche 2==>Eau - 2014
TypeSol = "eau"
annee = 2014
Rech = 0
For Each ele In dico.keys
    If CInt(Split(ele, "-")(1)) = annee And UCase(dico.Item(ele)) = UCase(TypeSol) Then
        Rech = Rech + 1
    End If
Next ele
Range("H3") = Rech

'Recherche 3==>Sable - 2013
TypeSol = "Sable"
annee = 2013
Rech = 0
For Each ele In dico.keys
    If CInt(Split(ele, "-")(1)) = annee And UCase(dico.Item(ele)) = UCase(TypeSol) Then
        Rech = Rech + 1
    End If
Next ele
Range("G4") = Rech

'Recherche 4==>Sable - 2014
TypeSol = "Sable"
annee = 2014
Rech = 0
For Each ele In dico.keys
    If CInt(Split(ele, "-")(1)) = annee And UCase(dico.Item(ele)) = UCase(TypeSol) Then
        Rech = Rech + 1
    End If
Next ele
Range("H4") = Rech

'Recherche 3==>Terre- 2013
TypeSol = "Terre"
annee = 2013
Rech = 0
For Each ele In dico.keys
    If CInt(Split(ele, "-")(1)) = annee And UCase(dico.Item(ele)) = UCase(TypeSol) Then
        Rech = Rech + 1
    End If
Next ele
Range("G5") = Rech

'Recherche 4==>Terre- 2014
TypeSol = "Terre"
annee = 2014
Rech = 0
For Each ele In dico.keys
    If CInt(Split(ele, "-")(1)) = annee And UCase(dico.Item(ele)) = UCase(TypeSol) Then
        Rech = Rech + 1
    End If
Next ele
Range("H5") = Rech

End Sub
 

Discussions similaires

Réponses
3
Affichages
230
Réponses
10
Affichages
448

Statistiques des forums

Discussions
312 337
Messages
2 087 392
Membres
103 536
dernier inscrit
komivi