Sub Compte_Couleurs()
Dim d, c As Range, coul&, a, b, i, mes
Set d = CreateObject("Scripting.Dictionary")
For Each c In ActiveSheet.UsedRange
If c.Interior.ColorIndex <> xlNone Then
coul = c.Interior.Color
d(coul) = d(coul) + 1 'comptage
End If
Next
If d.Count Then
a = d.keys
b = d.items
For i = 0 To UBound(a)
mes = mes & vbLf & "Code " & a(i) & vbTab & "Nombre " & b(i)
Next
End If
MsgBox IIf(d.Count, Mid(mes, 2), "Aucune couleur"), , "Couleurs"
End Sub
Bonsoir jmpat, bienvenue sur XLD,
Cette macro compte les couleurs de fond du UsedRange :
A+VB:Sub Compte_Couleurs() Dim d, c As Range, coul&, a, b, i, mes Set d = CreateObject("Scripting.Dictionary") For Each c In ActiveSheet.UsedRange If c.Interior.ColorIndex <> xlNone Then coul = c.Interior.Color d(coul) = d(coul) + 1 'comptage End If Next If d.Count Then a = d.keys b = d.items For i = 0 To UBound(a) mes = mes & vbLf & "Code " & a(i) & vbTab & "Nombre " & b(i) Next End If MsgBox IIf(d.Count, Mid(mes, 2), "Aucune couleur"), , "Couleurs" End Sub