Forum Discussion

Danilowyss's avatar
Danilowyss
Copper Contributor
Feb 05, 2022

somme si la couleur de fond est identique

Bonjour, J'aimerai additionner la somme des cellules qui ont une couleurs de fond identique. Est ce qu il y a une formule pour ça?

merci beaucoup.

D.

1 Reply

  • Danilowyss 

    Il n'y a pas de fonction intégrée pour cela, mais vous pouvez utiliser une fonction VBA:

    Function SommeCouleur(Plage As Range, Couleur As Range, Optional SommePlage As Range)
        Dim i As Long
        Dim c As Long
        Dim Somme As Double
        Application.Volatile
        On Error GoTo ErrHandler
        If SommePlage Is Nothing Then
            Set SommePlage = Plage
        End If
        c = Couleur.Interior.Color
        For i = 1 To Plage.Count
            If Plage(i).Interior.Color = c Then
                If IsNumeric(Plage(i).Value) Then
                    Somme = Somme + SommePlage(i).Value
                End If
            End If
        Next i
        SommeCouleur = Somme
        Exit Function
    ErrHandler:
        SommeCouleur = CVErr(xlErrValue)
    End Function

    Utilisation:

    =SommeCouleur(A1:B20;D1)

    où D1 est une cellule avec la couleur de fond que vous souhaitez utiliser.