Changing Cell Background Color Using RGB Color Code In A Macro

miketurn

Active Member
Joined
Dec 8, 2016
Messages
268
Hello Everyone,

(Excel 2003)
I am having a little trouble with using custom RGB Code colors within macros.

Okay, so when I.....
1.) select "Tools" from my Menu Bar
2.) select "Options"
3.) select "Color" tab
4.) select "Modify" button
5.) select "Standard" tab
When in this "Standard" tab it displays a hexagon of color swatches.
At its center you have the color "white"
The next color to the right of the color "white" is a light pink, select it
6.) (after selecting the light pink) go into the "Custom" tab which shows you the RGB Color numbers for that specific light pink color which is (RED 255, GREEN 204, BLUE 255)

If you assign this light pink color to one of your default Excel "Standard Colors" it works fine when you apply this color to a cells background.

When using the following macro, it comes out white?

Code:
Sub Color_LightPink
Selection.Interior.Color = RGB(255, 204 255)
End Sub

To test if this code works, I tried a couple of other numbers which work, such as the following macro which produces a "red" background.

Code:
Sub Color_Red
Selection.Interior.Color = RGB(255, 0, 0)
End Sub

Does anyone know why the light pink color code does not work?
Thank You to anyone who reads this.
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
@Guru008
Thank You for your response, but when I type in those values it produces the darker pink that Excel provides by default.
The (255, 204, 255) pink I am looking to achieve is a very light, more muted pink.
All the other colors in Excels default color grid have a very light, muted version at the bottom, the pink is the only one that doesn't by default.

If you or anyone else have any ideas of why this can be achieved in the color tabs method but not by macro, please let me know.
As I mentioned it does work by altering Excels default color palette, but I was hoping to achieve this in a macro to not have to mess with Excels default colors if possible.
Thanks Again
 
Last edited:
Upvote 0
@Guru008
By any chance did you or anyone else try the macro below? I was just wondering if this works for anyone else or if Excel does not accept all RGB color codes?
It should produce a very light pink background color.

Code:
Sub Color_LightPink
Selection.Interior.Color = RGB(255, 204 255)
End Sub


Thank You
 
Last edited:
Upvote 0
It does .....but your missing a comma after 204 !!!
 
Upvote 0
@Michael
In my first post I had typed it out manually and by the time I had realized that I was missing a comma I could not change it on the forum.
I then made the same mistake by copying it from my post #1 to post #4.

Thank You, but...
That being said in my Excel I have the comma! and it does not work for me, it just makes the cell background white.
For example if you have a yellow background set and you activate this macro it turns the cells background color white.

Did you actually try it, or did you just make an observation of the comma missing? When you run this macro with the comma added does it produce a light pink for you?
 
Upvote 0
@Michael
Thank You for getting back to me, in one regard I am glad to hear that it works, but in another I am not because I am still left with the question, why is it not working for me?

Do you or anyone else know what could cause something like this?
 
Upvote 0
Can you upload your workbook to dropbox ??
Is there conditional formatting involved in any of the selection ??
 
Upvote 0
Probably isn't the workbook, because I have tried it in many files.
I really don't want to have to re-install Excel just for something like this but I am really curious to see if it will fix it.
So weird though because I can't really see what would ever cause something like this.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

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