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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

HarryS

Board Regular
Joined
May 2, 2008
Messages
202
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.
 

HarryS

Board Regular
Joined
May 2, 2008
Messages
202
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
 

danieljharvey

New Member
Joined
Apr 24, 2008
Messages
17
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)
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,709
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Code:
ActiveSheet.Shapes("Rect1").Fill.ForeColor.RGB = RGB(255, 0, 0)
should do it.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,804
Messages
5,638,450
Members
417,025
Latest member
MusterDuster

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
Top