Changing shape colors

danieljharvey

New Member
Joined
Apr 24, 2008
Messages
17
Hi,

I have some code to make cell colours change incrementally, but Excel will only let me change it to the colours in the palette.

I have heard you can use Shapes instead and these are not affected by the palette. I have created "Rect1" to "Rect9", so how would I go about changing their color to an RGB value in VBA code?

Cheers
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
note if you are changing an object's colourindex then the range
is 0 to 51 but you can cycle this using

.colorindex = nn mod 50

These objects also have a property color which is a long

. color = 345643
or
. color = RGB(34,6,255)
rbg in range 0 to 255
you can get at a cells color directly

cells(4,5).background.color= rgb(4,240,6)
etc.
 
Upvote 0
maybe cells need
cells(4,7).interior.color = 34342
or
cells(4,8).interior.color = rgb(123,145,0)


to color parts of the text in a cell needs reference to
the cells characters
 
Upvote 0
Cheers, it's the shapes I'll need to change as I'm using Excel 2003 so it won't let me change to colours outside the palette with cell colouring.

So would this be the code to change a shape Red, for instance?

ActiveSheet.Shapes("Rect1").Color = RGB(255,0,0)
 
Upvote 0
Code:
ActiveSheet.Shapes("Rect1").Fill.ForeColor.RGB = RGB(255, 0, 0)
should do it.
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,242
Members
448,951
Latest member
jennlynn

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