Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting Cell background color

Status
Not open for further replies.

HughLerwill

Programmer
Nov 22, 2004
1,818
GB
Dear all,

When I do;

UserForm1.TextBox1.BackColor = RGB(128, 255, 128)Sheet1.Cells(1, 1).Interior.Color = RGB(128, 255, 128)

The textbox gets coloured as intended (a mid green), the Cell however ends up Grey.

UserForm1.TextBox1.BackColor = RGB(205, 231, 231)'a light blue
Sheet1.Cells(1, 1).Interior.Color = RGB(205, 231, 231)

works more successfully but the shades of blue produced in the Textbox and Cell are slightly different.

What's going on? Any ideas?

regards Hugh,
 
I read the following from a newsgroup

Excel is capable of displaying only 56 colors at a time (it's color
palette). The default color palette contains 46 different colors - 10
of them are duplicated.

If you use VBA to specify an RGB color that's not in the palette, Excel will
use the closest match. In other words, if you write a macro to change a
cell's color using RGB values, there is no guarantee that the actual color
will be displayed.


 
taupirho,

Thanks for that, I suspected as much. The following seems to get around the problem;

UserForm1.TextBox1.BackColor = RGB(128, 255, 128)
'modify default palette
ActiveWorkbook.Colors(37) = RGB(128, 255, 128)
Sheet1.Cells(1, 1).Interior.ColorIndex = 37

regards Hugh,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top