I have several cells, each with a different font and background colour. I am wondering if it is possible for me to extract the RGB value of the font/background colour of each cell and how I would do this?
I have several cells, each with a different font and background colour. I am wondering if it is possible for me to extract the RGB value of the font/background colour of each cell and how I would do this?
Last edited by icu222much; 07-02-2010 at 07:15 PM.
Welcome to the forum
![]()
Please Login or Register to view this content.
Entia non sunt multiplicanda sine necessitate
This bit of code will show the colorindex for the A1![]()
Please Login or Register to view this content.
Thank you for the speedy reply guys.
I tried the code but it just gave me 2 wierd numbers. I have set my cell A1 with font colour Red, and background colour Yellow. It reported that my font colour is 66047and my background colour is 65535. This does not seem to be RGB values unless there is some wierd converstion thing that is happening that I am unaware of.
From my understanding, ColorIndex only allows me to play with pre-determind Excel values. Am I correct? Almost all of my colours will be outside of this range I believe.
RGB values are stored as eight bits each in a long: 00BBGGRR. See if this speaks to you:
![]()
Please Login or Register to view this content.
Hello icu222much,
I wrote this macro to provide the RGB value for any Excel or System color value. It reurs the values in a single dimension array where subscript (0) = Red, (1) = Green, (2) = Blue. Copy this into a separate VBA module in your VB Project.
![]()
Please Login or Register to view this content.
Code Example
![]()
Please Login or Register to view this content.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
@ shg:
Your code seems to sort of work. It returns an incorrect hex value. My font colour is Red, but it kept on returning the hex representation of Teal. I further investigated the value and noticed that instead of getting RGB, I am getting BRG. That is still fine, as I can just move the values around to get RGB. Thank you sgh.
@ Leith Ross
Thank you for your code. When I went to run your code, I got a "Type Mis-match" error in the RGBTest() on the line "R = Color(0).
Last edited by shg; 07-01-2010 at 12:27 AM. Reason: deleted spurious quotes
I don't think so.It returns an incorrect hex value.
Only if the cell was formatted as teal and the red was the result of conditional fomatting.My font colour is Red, but it kept on returning the hex representation of Teal.
I don't think so.instead of getting RGB, I am getting BRG
Post a workbook that shows this.
I am home right now, so I have re-created the workbook. I have copied your code, and populated cell A1 with:
Font: Red
Background: Yellow
The hex that is reported is:
Font:
Background: Blue
Background: Teal
Link to workbook:
http://www.sfu.ca/~jca41/stuph/testA.xls
When I run this:
... on that workbook, this prints in the Immediate window:![]()
Please Login or Register to view this content.
... which is exactly correct.![]()
Please Login or Register to view this content.
Hello icu222much,
What processor does your computer use?
Both my work and home computer uses E8400.
Hello icu222much,
Since your are Intel cpu's, all data is stored internally in 'little endian" format. Click this link to read more on this subject. It will help clear up the confusion.
A Long is a Long, irrespective of endianness.
As I said before, RGB values are stored as 00BBGGRR, meaning the red value is in the least significant eight bits, green in the next, blue in the next.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks