Type MyRgb
R As Double
V As Double
B As Double
End Type
Sub test()
Dim nb&, C1&, C2&, Cx1 As MyRgb, Cx2 As MyRgb, Px1&, Px2&, Px3&, Ecart As MyRgb
nb = 20
Cells(1, 1).Resize(nb, 2).Clear
C1 = vbRed: Cx1 = longToRGB(C1)
C2 = vbGreen: Cx2 = longToRGB(C2)
Ecart.R = (Cx2.R - Cx1.R) / (nb - 1): Ecart.V = (Cx2.V - Cx1.V) / (nb - 1): Ecart.B = (Cx2.B - Cx1.B) / (nb - 1)
Cx2 = Cx1
For i = 1 To nb
With Cx2
If i <> 1 Then .R = .R + Ecart.R: .V = .V + Ecart.V: .B = .B + Ecart.B
Cells(i, 1).Interior.Color = RGB(.R, .V, .B)
Debug.Print Cells(i, 1).Interior.Color, i
End With
Next
Cells(1, 2).Interior.Color = C1
Cells(nb, 2).Interior.Color = C2
Debug.Print Cells(1, 1).Interior.Color, Cells(nb, 1).Interior.Color, Cells(1, 2).Interior.Color, Cells(nb, 2).Interior.Color
End Sub
Function longToRGB(c) As MyRgb
With longToRGB
.R = c Mod 256
.V = ((c - .R) / 256) Mod 256
.B = Int(c / 65536)
End With
End Function