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!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top