![]() |
Setting cell colors using RGB( ) function
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? |
Setting cell colors using RGB( ) function
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 ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "haileybury" wrote in message ... 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? |
All times are GMT +1. The time now is 02:52 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com