Setting ColorIndex in VBA - inconsistent colours

SteveTheDinosaur

New Member
Joined
Dec 28, 2005
Messages
4
Hello eveybody.

I have the following VBA code in different modules in the same project:

Range("A4:I4").Select
With Selection.Interior
.ColorIndex = 40
.Pattern = xlSolid
End With

When the code is executed in one module, the cells are light grey, when I run the same code in another module, I get a sort of browny-orange.

How can this be?

Many thanks to anybody who can help!
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

DominicB

Well-known Member
Joined
Oct 3, 2005
Messages
1,569
Good afternoon SteveTheDinosaur

Excel can only use a colour palette of 58 colours, but these 58 colours can be picked from a choice of millions. Each workbook has it's own palette (which can be changed by going to Tools > Options, Color, Modify) and are saved along with the workbook.

This knowledge should now answer your question - if the same macro gives you two different results with two different workbooks, then colour 40 is different in each of the two workbooks.

HTH

DominicB
 

SteveTheDinosaur

New Member
Joined
Dec 28, 2005
Messages
4
Many thanks, DominicB.

I believe this is the answer to my problem. I have learned something new about Excel!

Your help is much appreciated!

Steve
 

Watch MrExcel Video

Forum statistics

Threads
1,119,136
Messages
5,576,295
Members
412,716
Latest member
Ardin
Top