Determining RGB values of each item in the Standard Color Palette

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,275
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

Nice for for somebody for a Friday afternoon! :)

I know how to use the 56 .ColorIndex values, and how to set an interior or font color to an RGB value, but does anyone know of a quick way to return the RGB value of each element in the Standard Color Palette (Excel 2016) to a cell in a worksheet range ,say A1:A500 ?

Setting the fill colour of each cell to its corresponding RGB value would be pretty cool, too!

Thanks in advance and have a nice weekend

Pete
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Do you mean something like this:

Code:
Sub colourList()
Dim n As Long
For n = 1 To 56
    With Cells(n, "A")
        .Value2 = ActiveWorkbook.Colors(n)
        .Interior.Color = ActiveWorkbook.Colors(n)
    End With
Next

End Sub
 
Upvote 0
If you want RGB values for fill color you can use a UDF as in the example below where column B gives the RGB values for the first 10 fill colors produced by Rory's code in column A.
Excel Workbook
AB
10R=0, G=0, B=0
216777215R=255, G=255, B=255
3255R=255, G=0, B=0
465280R=0, G=255, B=0
516711680R=0, G=0, B=255
665535R=255, G=255, B=0
716711935R=255, G=0, B=255
816776960R=0, G=255, B=255
9128R=128, G=0, B=0
1032768R=0, G=128, B=0
Sheet5



Code:
Function GetRGBFill(rCell) As String
'Returns the RGB values for fill of cell rcell
    Dim c As Long
    Dim R As Long
    Dim G As Long
    Dim b As Long
Application.Volatile
    c = rCell.Interior.Color
    R = c Mod 256
    G = (c \ 256) Mod 256
    b = (c \ 65536) Mod 256
    GetRGBFill = "R=" & R & ", G=" & G & ", B=" & b
End Function
 
Upvote 0
Thanks for the replies, chaps. What I was after was a way of trapping the RGB values of each of the colors in the hexagonal "Standard Colors" palette, rather than going through them one at a time, coloring a cell and trapping its RGB value using JoeMo's excellent function above.
Cheers
Pete
 
Upvote 0
Thanks for the replies, chaps. What I was after was a way of trapping the RGB values of each of the colors in the hexagonal "Standard Colors" palette, rather than going through them one at a time, coloring a cell and trapping its RGB value using JoeMo's excellent function above.
Cheers
Pete
Glad we could help - thanks for the reply.
 
Upvote 0
As the values in the standard palette seem to increment by 51, how about
Code:
Sub NewOrderFac33()
   Dim r As Long, g As Long, b As Long, x As Long
   For r = 0 To 255 Step 51
      For g = 0 To 255 Step 51
         For b = 0 To 255 Step 51
            x = x + 1
            Cells(x, 1).Interior.Color = RGB(r, g, b)
            Cells(x, 2).Value = "R=" & r & ", G=" & g & ", B=" & b
         Next b
      Next g
   Next r
End Sub
 
Upvote 0
Just realised it's not that simple. The palette only has about 120 colours, not the 216 my code gives.
 
Upvote 0
Looks like I'll just have to do it manually for each element of the palette, then - not to worry - thanks both for your interest.
Pete
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,485
Members
448,967
Latest member
visheshkotha

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