Change Shape Color RGB based on Database

jocker_boy

New Member
Joined
Feb 5, 2015
Messages
36
Hi,

I have already a VBA code that creates a organigram based on a table.
One of the column is called "Entity" and actually one part of the code is this:

Code:
        If (oType = "WBS" And oData(nItem, cOrgOffEntity) = "PT") Then
            oNode.TextFrame2.TextRange.Font.Bold = False
            
            With oNode.Shapes.Fill
                .Visible = msoTrue
                .ForeColor.RGB = RGB(192, 215, 155)
                .Solid
            End With

And works, if some rows have "PT" in the Colum "Entity" that shape will be fill with the color "RGB(192, 215, 155)".

What i would like, is to create a table in a diferent Sheet, for example "sheet2" where i have a Table (database) with 2 columns:
In cloumn A i would have the Entitys (example: PT, ENG, FR, SP, etc...) and in the column B for each Entity i will fill with a diferent color.

My goal is substitute the "PT" for column A and the RGB(192,215,155) for the correspondent color in column B.

i found already this code, maybe it could help:

Code:
 Function            Color
'   Purpose             Determine the Background Color Of a Cell
'   @[B][URL="https://www.mrexcel.com/forum/members/param.html"]param[/URL][/B] rng          Range to Determine Background Color of
'   @[B][URL="https://www.mrexcel.com/forum/members/param.html"]param[/URL][/B] formatType   Default Value = 0
'                       0   Integer
'                       1   Hex
'                       2   RGB
'                       3   Excel Color Index
'   Usage               Color(A1)      -->   9507341
'                       Color(A1, 0)   -->   9507341
'                       Color(A1, 1)   -->   91120D
'                       Color(A1, 2)   -->   13, 18, 145
'                       Color(A1, 3)   -->   6
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function Color(rng As Range, Optional formatType As Integer = 0) As Variant
    Dim colorVal As Variant
    colorVal = Cells(rng.Row, rng.Column).Interior.Color
    Select Case formatType
        Case 1
            Color = Hex(colorVal)
        Case 2
            Color = (colorVal Mod 256) & ", " & ((colorVal \ 256) Mod 256) & ", " & (colorVal \ 65536)
        Case 3
            Color = Cells(rng.Row, rng.Column).Interior.ColorIndex
        Case Else
            Color = colorVal
    End Select
End Function


Many thanks,

Goncalo
 
Last edited:

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

jocker_boy

New Member
Joined
Feb 5, 2015
Messages
36
I have added this:

Code:
    Dim COD1 As Variant
    Dim COD2 As Variant
    Dim COD3 As Variant
    
    COD1 = Worksheets("Entity").Cells(2, "A").Value
    COD2 = Worksheets("Entity").Cells(3, "A").Value
    COD3 = Worksheets("Entity").Cells(4, "A").Value

With this:

Code:
If (oType = "OBS" And oData(nItem, cOrgOffEntity) = COD1) Then
            oNode.TextFrame2.TextRange.Font.Bold = False
            
            With oNode.Shapes.Fill
                .Visible = msoTrue
                .ForeColor.RGB = RGB(196, 215, 155)
                .Solid
            End With
        
        End If
        
        If (oType = "OBS" And oData(nItem, cOrgOffEntity) = COD2) Then
            oNode.TextFrame2.TextRange.Font.Bold = False
            
            With oNode.Shapes.Fill
                .Visible = msoTrue
                .ForeColor.RGB = RGB(252, 213, 182)
                .Solid
            End With
        
        End If
        
        If (oType = "OBS" And oData(nItem, cOrgOffEntity) = COD3) Then
            oNode.TextFrame2.TextRange.Font.Bold = False
            
            With oNode.Shapes.Fill
                .Visible = msoTrue
                .ForeColor.RGB = RGB(218, 150, 148)
                .Solid
            End With

Enf If

It's not the best solution, but i need to add at least 10 row's in my database, and with this code i have to copy and paste 10 times, one for each row.
And it still not resolve the problem to get the RGB color and insert that color in the correspondent ForeColor.RGB.

Thanks,
 

Watch MrExcel Video

Forum statistics

Threads
1,128,111
Messages
5,628,766
Members
416,337
Latest member
tl3phd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top