Fill 3 columns with RGB value of preceding columns Interior Colour

nicksoph

Board Regular
Joined
Jun 13, 2009
Messages
57
Im trying to fill 3 cells with the rgb values of the interior colour of the preceding cell, eg if cell A1 has a solid blue background then B1 would equal 0, C1=0 and D1=255. Found this code on this site;
Code:
Function FillColorRGBArray(Target As Range) As Variant
Dim N As Double, A(3) As Integer
    N = Target.Interior.Color
    A(0) = N Mod 256
    A(1) = Int(N / 256) Mod 256
    A(2) = Int(N / 256 / 256) Mod 256
    FillColorRGBArray = A
End Function
and can use it in the gui by entering the formula =FillColourRGBArray(a1) and pressing ctrl+shift+enter with B2:D2 selected but I cant get the syntax right in VBA and wonder if someone can give an example of how to use this array function. My code currently looks like this;
Code:
rng=Range("B1:D1")
rng=FillColorRGBArray("a1")
and produces a compile error - Type mismatch

Any help appreciated
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You would need:

Code:
    Set Rng = Range("B1:D1")
    Rng.Value = FillColorRGBArray(Range("a1"))
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,194
Members
448,554
Latest member
Gleisner2

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