Sub New_Color()

F

Fan924

Sub New_Color()
ActiveWorkbook.Colors(4) = RGB(255, 0, 0)
End Sub

This works great. It changes color pallet number 4 to red.
When I put 255, 0, 0 in a cell and replace it with a variable, I get
black [not red] or an error message highlighting RGB. Any ideas?
 
D

Dave Peterson

VBA's RGB argument expects 3 parms passed to it (Red:=, Green:=, blue:=)--not a
string.

So you could parse your string and separate it into 3 different variables.

Personally, I think putting each of the values into separate cells would be
easier:

with activesheet
.parent.colors(4) = rgb(.range("A1").value, _
.range("B1").value, _
.range("C1").value)
end with

(The sheet's parent is the workbook that owns that sheet.)

Sub New_Color()
ActiveWorkbook.Colors(4) = RGB(255, 0, 0)
End Sub

This works great. It changes color pallet number 4 to red.
When I put 255, 0, 0 in a cell and replace it with a variable, I get
black [not red] or an error message highlighting RGB. Any ideas?
 

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