LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem setting RGB Values with ShapeRange

I am trying to usa a VBA macro in Excel to set the interior color of a
cell to a specific RGB value. I want to show a user the apparent color
of a computed RGB value with an accompanying cell or box.

My initial thought was to pick the RGB value from the cells adjacent
to the cell I was trying to color with the following code.

Sub Macro2()
R = ActiveCell.Offset(0, -3)
G = ActiveCell.Offset(0, -2)
B = ActiveCell.Offset(0, -1)
With Selection.Interior
.Color = RGB(R, G, B)
.Pattern = xlSolid
End With
End Sub

This macro works exactly as I hoped, with the exception of the well
know problem that the color set is not the specific RGB value, but
rather the RGB color of the closest match in the color table.

Microsoft Knowledge Base Article 71781 (or 213201), "RGB Function May
Map to Unexpected Color" refers to this problem, and suggests the use
of the ShapeRange object collection instead to get around this
problem.

I tried this with the following code,

Sub Macro2()
R = ActiveCell.Offset(0, -3)
G = ActiveCell.Offset(0, -2)
B = ActiveCell.Offset(0, -1)
With Selection.ShapeRange.Fill.ForeColor.RGB =
RGB(R, G, B)
End With
End Sub

But get an error on the Selection Line.

I am not a VB programmer so am clueless as to what I am doing wrong.

Will the ShapeRange command only work on an inserted Shape rather than
a spreadsheet cell? This is OK, I can insert a rectangular box, but
how do I refer to the cells containing the RGB values?

Any help is much appreciated.

Bob



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting values in a cell Stephen Excel Discussion (Misc queries) 3 July 10th 08 08:23 PM
Selection.ShapeRange.IncrementLeft error Anil Khemchandani Excel Programming 1 December 9th 03 09:29 PM
Selection.ShapeRange.IncrementLeft error Anil Khemchandani Excel Programming 0 December 9th 03 07:30 PM
Problem with setting values for SeriesCollection Jon Peltier[_3_] Excel Programming 1 September 3rd 03 04:20 AM
Setting values in another workbook Ecco Excel Programming 1 July 17th 03 08:15 AM


All times are GMT +1. The time now is 07:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"