exemples ici : https://forum.excel-pratique.com/viewtopic.php?f=10&t=21547
ou alors
Dim posx As Integer, posy As Integer
Sub CreerPalette()
Dim i As Integer, j As Integer, k As Integer, n As Integer, Sh As Object
Dim r, g, b
r = Array(0, 255, 255, 0, 0, 255, 255, 0, 128, 0, 0, 128, 128, 0, 192, 128, 153, 153, 255, 204, 102, 255, 0, 204, 0, 255, 255, 0, 128, 128, 0, 0, 0, 204, 204, 255, 153, 255, 204, 255, 51, 51, 153, 255, 255, 255, 102, 150, 0, 51, 0, 51, 153, 153, 51, 51)
g = Array(0, 255, 0, 255, 0, 255, 0, 255, 0, 128, 0, 128, 0, 128, 192, 128, 153, 51, 255, 255, 0, 128, 102, 204, 0, 0, 255, 255, 0, 0, 128, 0, 204, 255, 255, 255, 204, 153, 153, 204, 102, 204, 204, 204, 153, 102, 102, 150, 51, 153, 51, 51, 51, 51, 51, 51)
b = Array(0, 255, 0, 0, 255, 0, 255, 255, 0, 0, 128, 0, 128, 128, 192, 128, 255, 102, 204, 255, 102, 128, 204, 255, 128, 255, 0, 255, 128, 0, 128, 255, 255, 255, 204, 153, 255, 204, 255, 153, 255, 204, 0, 0, 0, 0, 153, 150, 102, 102, 0, 0, 0, 102, 153, 51)
position True
taille = 12
supp True
For i = 1 To 8
For j = 1 To 7
With ActiveSheet.Shapes.AddShape(msoShapeRectangle, posx + taille * (i - 1), posy + taille * (j - 1), taille, taille)
.Name = "palette" & i * j
'.TextFrame.Characters.Text = CStr(i * j)
'.TextFrame.Characters.Font.ColorIndex = 1 ' ou 2
.Fill.ForeColor.RGB = RGB(r(i * j - 1), g(i * j - 1), b(i * j - 1))
.OnAction = "'Colorier(" & i * j & ")'"
End With
Next
Next
End Sub
Sub position(ok As Boolean)
On Error GoTo fin
With Selection.Offset(1, 1)
posx = .Left + 2: posy = .Top + 2
End With
Exit Sub
fin:
posx = 400: posy = 100
End Sub
Sub colorier(n As Integer)
Dim p
p = Array(2, 1, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
Selection.Interior.ColorIndex = n
Selection.Font.ColorIndex = p(n - 1)
supp True
End Sub
Sub supp(ok As Boolean)
For Each Sh In ActiveSheet.Shapes
Sh.Delete
Next
End Sub