Apply conditional formatting to all shapes on a sheet

Knockoutpie

Board Regular
Joined
Sep 10, 2018
Messages
116
Office Version
  1. 365
Platform
  1. Windows
Is there any way to apply conditional formatting to all shapes in a sheet?

I have about 100 ovals who's shape names range from "oval 1" to "oval 100" etc..

The ovals all reference a cell which will return a number 1-4

is there a way to apply conditional formatting to these? 1 = green, 2 = yellow, 3 = orange, 4 = red..

1692036995960.png
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The ovals all reference a cell which will return a number 1-4
I have a couple of questions regarding your description:
- What kind of oval do you have, that is, how do you insert it into the sheet?
- How do you reference the cell?

Not possible with conditional formatting.

If you have a shape and within the shape the text "1", "2", "3" or "4" then run the following macro to color all the shapes on the sheet:


VBA Code:
Sub colorshape()
  Dim sh As Shape
  Dim n As Variant, s As Variant, nrgb As Variant
  
  Application.ScreenUpdating = False
  
  For Each sh In ActiveSheet.Shapes
    n = sh.AutoShapeType
    If n = 9 Then
      nrgb = ""
      s = sh.TextFrame2.TextRange.Text
      Select Case s
        Case "1": nrgb = RGB(0, 176, 80)    'green
        Case "2": nrgb = RGB(255, 255, 0)   'yellow
        Case "3": nrgb = RGB(255, 192, 0)   'orange
        Case "4": nrgb = RGB(255, 0, 0)     'red
      End Select
      
      If nrgb <> "" Then sh.Fill.ForeColor.RGB = nrgb
    End If
  Next
  Application.ScreenUpdating = True
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
 
Upvote 1
Solution
I have a couple of questions regarding your description:
- What kind of oval do you have, that is, how do you insert it into the sheet?
- How do you reference the cell?

Not possible with conditional formatting.

If you have a shape and within the shape the text "1", "2", "3" or "4" then run the following macro to color all the shapes on the sheet:


VBA Code:
Sub colorshape()
  Dim sh As Shape
  Dim n As Variant, s As Variant, nrgb As Variant
 
  Application.ScreenUpdating = False
 
  For Each sh In ActiveSheet.Shapes
    n = sh.AutoShapeType
    If n = 9 Then
      nrgb = ""
      s = sh.TextFrame2.TextRange.Text
      Select Case s
        Case "1": nrgb = RGB(0, 176, 80)    'green
        Case "2": nrgb = RGB(255, 255, 0)   'yellow
        Case "3": nrgb = RGB(255, 192, 0)   'orange
        Case "4": nrgb = RGB(255, 0, 0)     'red
      End Select
     
      If nrgb <> "" Then sh.Fill.ForeColor.RGB = nrgb
    End If
  Next
  Application.ScreenUpdating = True
End Sub


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
Dante, my guy, that works perfect.

You always have perfect answers.
 
Upvote 0
Hello, is there something I need to change to apply this to all shapes the text references a cell.
Each paddock on the map should change colour to the reference in the shape. This will be between 1 & 20.
Thanks
farm.jpg
 
Upvote 0
Sorry that last post wastnt clear.
As I am using the cell reference for my text cell and not the text.frame2 I need to change it to look at
's = sh.Shapes.Range(Array("Freeform 24")).Select.

Any ideas appreciated
 
Upvote 0

Forum statistics

Threads
1,215,157
Messages
6,123,340
Members
449,097
Latest member
thnirmitha

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