Shape Colour based on Value or Cell Fill color

naveeddil

New Member
Joined
Nov 5, 2015
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Dear All,

I have an excel sheet having some 30+ shapes which is making a map. I have given names to all the shapes as you can see in the below picture.
Xag3pif.png



What i like is that i would like to color the different shapes based on their value in a table.


Excel File: http://s000.tinyupload.com/download.php?file_id=57118960552482861011&t=5711896055248286101138391


Please Help
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I looked at your question yesterday and you said:
What i like is that i would like to color the different shapes based on their value in a table.

But did not give the name of the Table or in what column of the Table:

So is something like this "12" in column 3 of your Table named Table1 or are you talking about column "C" of a sheet name "Master"

We always need specific details like this.
 
Upvote 0
I watched the video (but have not looked at your workbook) and
- created 2 freeform shapes (as in the video)
- renamed them "Khyber" and "Bajour" (2 of the names you have given to your shapes)
- created a table of RGB values (see picture below)
- added the code below

The code loops all shapes in the active sheet and (if found in the table) colour-fills based on lookup RDG values
On Error Resume Next means that any shapes not in your table are ignored and the code continues to run

Code:
Sub ColourShapes()
    Dim shp As Shape, R As Long, B As Long, G As Long, aMatch As Range, Rng As Range
    Set Rng = Sheets("[COLOR=#ff0000][I]LookUpSheet[/I][/COLOR]").Range("A:A")
    For Each shp In ActiveSheet.Shapes
            On Error Resume Next
            Set aMatch = Rng.Find(shp.Name)
            On Error GoTo 0
            With aMatch
                R = aMatch.Offset(, 1)
                B = aMatch.Offset(, 2)
                G = aMatch.Offset(, 3)
            End With
            shp.Fill.ForeColor.RGB = RGB(R, B, G)
    Next shp
End Sub

Excel 2016 (Windows) 32 bit
A
B
C
D
E
1
NameRedBlueGreen
2
Khyber
255​
100​
0​
3
Bajour
0​
50​
255​
4
etc
5
6
Sheet: LookUpSheet
 
Last edited:
Upvote 0

But did not give the name of the Table or in what column of the Table:
So is something like this "12" in column 3 of your Table named Table1 or are you talking about column "C" of a sheet name "Master"



Thank You for bringing me to more specific.
In the attached spreadsheet, A table on the left is given with different values.
I would like that the shapes having names should be colored based on the values given in Column C.
The color could be based on the cell color (which is already having conditional formatting) OR based on the criteria given in G10:H13.
Example: If Bajour value in Cell C8 is 96% so the shape its shape should be Green filled. If the value of Bajour is Changed to 80% so the shape should be filled with red color.
 
Upvote 0
The code in post#4 works correctly, but would benefit from some editing :ROFLMAO:

the With.. is pointless
Code:
            With aMatch
                R = aMatch.Offset(, 1)
                B = aMatch.Offset(, 2)
                G = aMatch.Offset(, 3)
            End With
unless written like this ....
Code:
            With aMatch
                R = .Offset(, 1)
                B = .Offset(, 2)
                G = .Offset(, 3)
            End With
 
Upvote 0
I never open links on this forum to look at user files. And I do not look at videos to see what a user needs. I always like written out details.
[/LEFT]


Thank You for bringing me to more specific.
In the attached spreadsheet, A table on the left is given with different values.
I would like that the shapes having names should be colored based on the values given in Column C.
The color could be based on the cell color (which is already having conditional formatting) OR based on the criteria given in G10:H13.
Example: If Bajour value in Cell C8 is 96% so the shape its shape should be Green filled. If the value of Bajour is Changed to 80% so the shape should be filled with red color.
 
Upvote 0
I never open links on this forum to look at user files. And I do not look at videos to see what a user needs. I always like written out details.

If you dont open files and focus on written details so what is your feedback on it :(
 
Upvote 0
You said:

in the attached spreadsheet, A table on the left is given with different values.

I never open other peoples spreadsheets.

If you dont open files and focus on written details so what is your feedback on it :(
 
Upvote 0
Excel 2016 (Windows) 32 bit

<tbody>
</tbody>
Sheet: LookUpSheet

<tbody>
</tbody>

Thank you for the coding and it is working.
Although it is coloring the shape based on the RGB values. I would like to update the shape fill colors based on some coverage value and only four colors i.e. Red, Orange, Green and Grey. (No more colors)

The Coloring should be based on below ranges:

Range
Color name
<90%Red
90%~95%Orange
95%~105%Green
>105%Grey

<tbody>
</tbody>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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
Back
Top