Colors

G

Geoff

Hi
I have put the hex values of colors into Range("A1:A5").
&H0&
&HFFFFFF&
&HFF&
&HFF00&
&HFF0000&

How can i iterate through the range and use the hex value? The code below
fails with 'Mismatch'

Dim frm,frmcolor
For i =1 to 5
frmcolor = Sheets(1).Cells(i , 1).Value
frm.BackColor = frmcolor
Next

Appreciate any help.

T.I.A.

Geoff
 
P

Peter T

Hi Geoff,

You need to coerce the Hex string to a value

frmcolor = Val(Sheets(1).Cells(i, 1).Value)

Be aware that in vba colours are read from Hex as BGR, not RGB as in html
#RRGGBB. However your sample colours correctly define pure black, white,
red, green & blue.

Regards,
Peter T
 
B

Bob Phillips

You can use RGB to be consistent

Activecell.Interior.Color = RGB(&hff,&h0,&h0)

3 questions on colour today already :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top