Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Convert RGB to Red/Green/Blue component

I've seen this somewhere, but can't find it now. Can someone direct me to
the formulas to convert to R/G/B components.

Thanks,
Barb Reinhardt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Convert RGB to Red/Green/Blue component

Barb,

You can adapt the following code:

Dim R As Long
Dim G As Long
Dim B As Long
Dim RGBLong As Long
R = &H10
G = &H20
B = &H30
RGBLong = RGB(R, G, B)
Debug.Print Hex(RGBLong)
R = RGBLong And &HFF
G = (RGBLong And &HFF00&) \ &H100&
B = (RGBLong And &HFF0000) \ &H10000
Debug.Print Hex(R), Hex(G), Hex(B)

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Mon, 6 Apr 2009 08:04:15 -0700, Barb Reinhardt
wrote:

I've seen this somewhere, but can't find it now. Can someone direct me to
the formulas to convert to R/G/B components.

Thanks,
Barb Reinhardt

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Convert RGB to Red/Green/Blue component

Here's one version:

Public Function LongToRGB(theColor As Long, iRed As Integer, iGreen As
Integer, iBlue As Integer) As Boolean
'
Dim lColor As Long
lColor = theColor 'work long
iRed = lColor Mod 256 'get red component
iGreen = (lColor \ 256) Mod 256 'get green component
iBlue = (lColor \ 256 \ 256) Mod 256 'get blue component
'
LongToRGB = True
End Function


HTH,

Eric

"Barb Reinhardt" wrote:

I've seen this somewhere, but can't find it now. Can someone direct me to
the formulas to convert to R/G/B components.

Thanks,
Barb Reinhardt

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Convert RGB to Red/Green/Blue component

Here is one more method...

Dim Red As Long
Dim Green As Long
Dim Blue As Long
Dim HexVal As String

HexVal = Hex(rgbValue)
Red = CLng("&H" & Right(HexVal, 2))
Green = CLng("&H" & Mid(HexVal, 3, 2))
Blue = CLng("&H" & Left(HexVal, 2))

Debug.Print Red, Green, Blue

--
Rick (MVP - Excel)


"Barb Reinhardt" wrote in message
...
I've seen this somewhere, but can't find it now. Can someone direct me to
the formulas to convert to R/G/B components.

Thanks,
Barb Reinhardt


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Convert RGB to Red/Green/Blue component

Note that when using HEX values that Microsoft handles the HEX values in
reverse order.

All others (HTML, VB RGB Functions, etc.) = R,G,B

Microsoft Hex value is --- B,G,R




"Barb Reinhardt" wrote in message
...
I've seen this somewhere, but can't find it now. Can someone direct me to
the formulas to convert to R/G/B components.

Thanks,
Barb Reinhardt



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to understand yellow input, green is calc, what is blue? Dan Greenlee Excel Discussion (Misc queries) 1 November 29th 09 11:28 AM
How to replace the background color of all cells from light green to light blue? Claudia d'Amato Excel Programming 5 November 15th 08 12:11 AM
How to replace the background color of all cells from light green to light blue? Claudia d'Amato Excel Discussion (Misc queries) 1 November 14th 08 07:09 PM
Blue to Green and Back to Green Loadmaster Excel Discussion (Misc queries) 5 August 15th 08 12:33 AM
The Excel 2007 Office Convert function sometimes gives me blue scr TomThumb Excel Programming 0 March 5th 07 05:50 PM


All times are GMT +1. The time now is 02:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"