ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Convert RGB to Red/Green/Blue component (https://www.excelbanter.com/excel-programming/426501-convert-rgb-red-green-blue-component.html)

Barb Reinhardt

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

Chip Pearson

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


egun

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


Rick Rothstein

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



David

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





All times are GMT +1. The time now is 10:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com