One other thing,
If you are curious about the exact default mapping between color
indices and RGB values, copy the following into a new workbook and run
it:
Sub ShowColors()
'Based on fact that
'RGB(R, G, B) = 65536 * B + 256 * G + R
Dim i As Long, C As Long
Dim R As Long, G As Long, B As Long
Range("A1").Value = "Index"
Range("B1").Value = "Color"
Range("C1").Value = "R"
Range("D1").Value = "G"
Range("E1").Value = "B"
Range("F1").Value = "Check"
For i = 1 To 56
Range("A1").Offset(i, 0).Value = i
Range("B1").Offset(i, 0).Interior.ColorIndex = i
C = Range("B1").Offset(i, 0).Interior.Color
R = C Mod 256
G = ((C - R) Mod 65536) / 256
B = (C - 256 * G - R) / 65536
Range("C1").Offset(i, 0).Value = R
Range("D1").Offset(i, 0).Value = G
Range("E1").Offset(i, 0).Value = B
Range("F1").Offset(i, 0).Interior.Color = RGB(R, G, B)
Next i
End Sub
Take care
-John
RichardSchollar wrote:
> John - thanks for your help (took a while replying cos the forum I
> usually access this board from seems to have disappeared).
>
> Tom - thanks for the explain too. Thanks to both of you I now know an
> awful lot more about colour manipulation in Excel spreadsheets (and the
> inherent limitations).
>
> I take it that the 56 colour limit may not apply if you imbed say a
> JPEG in the sheet? It doesn't seem to, but that could possibly be down
> to my tired old eyes...
>
> Best regards
>
> Richard
>
>
>
> Tom Ogilvy wrote:
> > There would be no advantage to restricting the cell to 56 colors if Excel
> > retained the RGB colors. It only stores the colorindex - which it must do
> > for every cell it maintains information about.
> >
> > So you would need to change the palette first.
> >
> > --
> > Regards,
> > Tom Ogilvy
> >
> >
> > "John Coleman" wrote:
> >
> > > Richard,
> > >
> > > You need to explicitly change the palette in order to display a color
> > > not on the palette (although I don't know if it strictly *has* to be
> > > before you execute something like Range("A1").Interior.Color =
> > > RGB(12,13,14) if the RHS is not on the palette, though I suspect it
> > > does. I can't imagine why Excel would store more color information for
> > > a cell than it can currently display). It doesn't seem to be
> > > well-documented. I only discovered the limitation when I wanted an
> > > effect that required the shading of cells to range smoothly from black
> > > to white.
> > >
> > > -John
> > >
> > > RichardSchollar wrote:
> > > > John
> > > >
> > > > I think I get it - so what you're saying is that you need to update the
> > > > palette *before* applying it to a sheet? Otherwise, the applied color
> > > > will default to, I presume, the closest match from the existing
> > > > palette? Am I understanding your point correctly?
> > > >
> > > > Thanks & kind regards
> > > >
> > > > Richard
> > > >
> > > >
> > > > --
> > > > RichardSchollar
> > > > ------------------------------------------------------------------------
> > > > RichardSchollar's Profile: http://www.officehelp.in/member.php?userid=5248
> > > > View this thread: http://www.officehelp.in/showthread.php?t=1275010
> > > >
> > > > Posted from - http://www.officehelp.in
> > >
> > >