Option Explicit
'===================
Sub Manip_Couleur()
Dim x%, IntColor&, ValCol&, Lg%, Col1%
Dim HexDigits
Dim Blue%, Green%, Red%
Lg = 10: Col1 = 3
x = Cells(10, 2).Value 'mettre une valeur d'index couleur en (B10)
Cells(1, Col1).ColumnWidth = 3
Columns("C:C").HorizontalAlignment = xlCenter
Cells(1, Col1).Font.Bold = True
Cells(Lg, Col1).Interior.ColorIndex = x
Cells(Lg, Col1).Value = x
IntColor = Cells(Lg, Col1).Interior.Color
HexDigits = Hex(IntColor)
Call Calcul_RGB(HexDigits, Blue, Green, Red)
ValCol = CDbl(Blue) + CDbl(Green) + CDbl(Red)
Cells(Lg, Col1 + 1).Value = "RGB (" & Red & "," & Green & "," & Blue & ")"
If ValCol > 256 Then
Cells(Lg, Col1).Font.ColorIndex = 1
Else
Cells(Lg, Col1).Font.ColorIndex = 2
End If
End Sub
'====================
Sub Calcul_RGB(ByVal HexDigits As Variant, Blue%, Green%, Red%)
Do Until Len(HexDigits) = 6
HexDigits = "0" & HexDigits
Loop
Blue = Val("&h" & Left(HexDigits, 2))
Green = Val("&h" & Mid(HexDigits, 3, 2))
Red = Val("&h" & Right(HexDigits, 2))
End Sub
'====================