Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionFunction SommeCouleur(Plage As Range, CelCouleur As Range) As Long Dim Couleur As Long Couleur = CelCouleur.Interior.ColorIndex For Each Cell In Plage If Cell.Interior.ColorIndex Couleur Then SommeCouleurs SommeCouleurs + 1 Next End Function
Public Function SommeCouleur(Plage As Range, CelCouleur As Range) As Long
Public Function SommeCouleurs(Plage As Range, CelCouleur As Range) As Long Dim Couleur As Long Dim mCell As Object ' Variable renommée car 'Cell' est un mot clé du langage Couleur = CelCouleur.Interior.ColorIndex For Each mCell In Plage If mCell.Interior.ColorIndex Couleur Then SommeCouleurs SommeCouleurs + 1 Next End Function
Private Sub CommandButton1_Click() Range("A1").Value = SommeCouleurs(Range(maZoneATester), Range(maCelluleColorisée)) End Suboù maZoneATester est le Range des cellules à tester, genre "A1:B77" ou "A:V" ...
Public Function SommeCouleurs(Plage As Range, maCouleur As Variant) As Long Dim mCell As Object ' Variable renommée car 'Cell' est un mot clé du langage For Each mCell In Plage If mCell.Interior.ColorIndex maCouleur Then SommeCouleurs SommeCouleurs + 1 Next End Functionet pour l'appeler :
Private Sub CommandButton1_Click() Range("A1").Value = SommeCouleurs(Range(maZoneATester), 38) End Suboù "38" est la couleur rose.
Function SommeInferrieur(Plage As Range, Valeur As Integer) As Long For Each Cell In Plage If Cell.Value < Valeur Then SommeInferrieur = SommeInferrieur + 1 Next End Function Function SommeSuperrieur(Plage As Range, Valeur As Integer) As Long For Each Cell In Plage If Cell.Value > Valeur Then SommeSuperrieur = SommeSuperrieur + 1 Next End Function Function SommeCompriEntre(Plage As Range, ValeurMin As Integer, ValeurMax As Integer) As Long For Each Cell In Plage If Cell.Value > ValeurMin And _ Cell.Value < ValeurMax Then SommeCompriEntre = SommeCompriEntre + 1 Next End Function