OilEconomist
Active Member
- Joined
- Dec 26, 2016
- Messages
- 421
- Office Version
- 2019
- Platform
- Windows
Thanks in advance for any assistance provided. I am trying to use an existing cells Interior Color Index number to shade other cells, but the color it retrieves is different.
Why is the color different and how can I get the actual color?
I tried to use a function where I can obtain the RGB color code to see if it will give me a more accurate color index, but how do I convert the string to a color?
So why am I getting an error on the following line:
Range("C10")
is the existing color. When I retrieve it and use it on Range("D10")
, I get what is shownTrading Videos - (Active).xlsm | ||||
---|---|---|---|---|
C | D | |||
10 | ||||
Al.Brooks (2) |
Why is the color different and how can I get the actual color?
I tried to use a function where I can obtain the RGB color code to see if it will give me a more accurate color index, but how do I convert the string to a color?
So why am I getting an error on the following line:
VBA Code:
Range("D10").Interior.ColorIndex = Evaluate(ColorRGB_Is)
VBA Code:
Option Explicit
Public Sub ColorTest()
Dim Rng As Range
Dim ColorRGB_Get As String
Dim ColorRGB_Is As Variant
Dim ClrInt As Long
Set Rng = Range("C10")
'ColorRGB_GetF(Rng As Range) As String
ColorRGB_Get = ColorRGB_GetF(Rng)
ColorRGB_Is = "RGB(" & ColorRGB_Get & ")"
Range("D10").Interior.ColorIndex = Evaluate(ColorRGB_Is)
End Sub
Function ColorRGB_GetF(Rng As Range) As String
Dim IntColor As Long
Dim RGB_Color As String
Dim c As Long
Dim r As Long
Dim G As Long
Dim b As Long
IntColor = Rng.Interior.Color
r = IntColor And 255
G = IntColor \ 256 And 255
b = IntColor \ 256 ^ 2 And 255
ColorRGB_GetF = r & ", " & G & ", " & b
End Function