Bonjour,
sur cette ligne le "= true" est de trop
If cellule1.Interior.ColorIndex = 6 = True Then
Je ne comprend pas bien l'utilité de total 2
Une solution pour faire l'addition de toutes les cellules jaune
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Function AdditionJaune(Plage1 As Range, Plage2 As Range) As Double
Dim rg As Range
Dim Total As Double
For Each rg In Plage1
If rg.Interior.ColorIndex = 6 Then Total = Total + rg.Value
Next
For Each rg In Plage2
If rg.Interior.ColorIndex = 6 Then Total = Total + rg.Value
Next
AdditionJaune = Total
End Function |
appel de la fonction
=AdditionJaune(A1:A12;C1:C12)
A noter que l'on pourrait avoir qu'une seule plage dans le code si on appelait comme suit
=AdditionJaune((A1:A12;C1:C12))
1 2 3 4 5 6 7 8 9 10 11 12 13
| Function AdditionJaune(Plage1 As Range) As Double
Dim rg As Range
Dim Total As Double
For Each rg In Plage1
If rg.Interior.ColorIndex = 6 Then Total = Total + rg.Value
Next
AdditionJaune = Total
End Function |
Partager