Setting cell colors using RGB( ) function

H

haileybury

I have a range of cells with different RGB values e.g.
Column 1
RGB(0,0,0)
RGB(0,255,0)

I am reading these values and in my macro and setting the color of a range
of cells
using the following statement.

rangec.Interior.Color = Worksheets("output").Cells(mrgb,
13).Value

I get an error message stating that VB is unable to set the color property
however when I hard code the value as below, the code works fine.

rangec.Interior.Color = RGB(0,255,0)

I did not want to hard code it because of the obvious reason ( for users to
change/add colours in the future)

I tries capturing the cell value in a variable ( tried string, variant) and
nothing worked. Also I tried vbRed; vbBlue etc instead of the RGB( ) function
and still the same behaviour.

Wondering if anyone has any tips?
 
J

Jon Peltier

VBA cannot interpret your text "RGB(0,0,0)". You could put R, G, and B into
adjacent cells and use this:

With Worksheets("output")
rangec.Interior.Color = RGB(.cells(mrgb,13), .cells(mrgb,14),
..cells(mrgb,15))
End With

- Jon
 

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