#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default RGB values

I am attempting to write some code that will in excel fill a cell with a user
created colour using RGB values.

basically the user will enter in the red, green and blue values in 3
seperate cells then i want to know how to write some code to get those RGB
values into a fill pattern and fill a cell with it?

example - r=20, g=145, b=250; then the cell will be populated with the
colour those RGB values create.

any one out there with a solution for me? if its possible i would prefer to
want some code i can simply type into a cell, if its avoidable i dont want to
use macros.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default RGB values

here's an example

Selection.Interior.Color = RGB(20,145,250)
will set the active cell's background to the specified RGB value

"benny" wrote:

I am attempting to write some code that will in excel fill a cell with a user
created colour using RGB values.

basically the user will enter in the red, green and blue values in 3
seperate cells then i want to know how to write some code to get those RGB
values into a fill pattern and fill a cell with it?

example - r=20, g=145, b=250; then the cell will be populated with the
colour those RGB values create.

any one out there with a solution for me? if its possible i would prefer to
want some code i can simply type into a cell, if its avoidable i dont want to
use macros.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default RGB values

Alvin:

example

Dim r As Double
Dim g As Double
Dim b As Double
Dim k As Long
For i = 1 To 56
Range("A" & i).Interior.ColorIndex = i
Range("B" & i) = i
k = Range("A" & i).Interior.Color
r = k Mod 256
b = Int(k / 65536)
g = Int((k - (b * 65536)) / 256)
Range("C" & i).Interior.Color = RGB(r, g, b)
Range("D" & i) = r & "," & g & "," & b
Next

--

http://www.vba.com.tw/plog/


"Alvin" wrote:

here's an example

Selection.Interior.Color = RGB(20,145,250)
will set the active cell's background to the specified RGB value

"benny" wrote:

I am attempting to write some code that will in excel fill a cell with a user
created colour using RGB values.

basically the user will enter in the red, green and blue values in 3
seperate cells then i want to know how to write some code to get those RGB
values into a fill pattern and fill a cell with it?

example - r=20, g=145, b=250; then the cell will be populated with the
colour those RGB values create.

any one out there with a solution for me? if its possible i would prefer to
want some code i can simply type into a cell, if its avoidable i dont want to
use macros.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default RGB values

Selection.Interior.Color = RGB(20,145,250)
will set the active cell's background to the specified RGB
value


Not quite. Excel is limited to a color pallet of 56 colors
(although you can choose any RGB color for inclusion in the
pallet). When you specify a value to the Color property, Excel
picks the closest color in its pallet to the one specified. You
are not guaranteed a match.

If you need an exact RGB color, you must first assign it to a
location in the pallet, and then use the ColorIndex to grab that
color. E.g.,

ThisWorkbook.Colors(56) = RGB(20,145,250)
Selection.Interior.ColorIndex = 56

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Alvin" wrote in message
...
here's an example

Selection.Interior.Color = RGB(20,145,250)
will set the active cell's background to the specified RGB
value

"benny" wrote:

I am attempting to write some code that will in excel fill a
cell with a user
created colour using RGB values.

basically the user will enter in the red, green and blue
values in 3
seperate cells then i want to know how to write some code to
get those RGB
values into a fill pattern and fill a cell with it?

example - r=20, g=145, b=250; then the cell will be populated
with the
colour those RGB values create.

any one out there with a solution for me? if its possible i
would prefer to
want some code i can simply type into a cell, if its avoidable
i dont want to
use macros.



Reply
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
Excel 2007 doesnt show Y-axis values when the values are small. outback Charts and Charting in Excel 2 October 26th 08 01:37 AM
Exclude #N/A values and Return Numeric values to consecutive cells in Single Row Sam via OfficeKB.com Excel Worksheet Functions 5 February 9th 08 03:07 AM
Search/Filter to find values in another range based on two cell values Andy Excel Programming 2 April 29th 04 04:08 PM
How do I search thr'o column and put unique values in differnt sheet and sum corresponding values in test test Excel Programming 3 September 9th 03 08:53 PM
Predict Y-values on new X-values based on other actual X and Y values? NorTor Excel Programming 2 August 10th 03 03:08 PM


All times are GMT +1. The time now is 11:10 PM.

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

About Us

"It's about Microsoft Excel"