Conditional Formatting Shapes that contains specific words

liberovago

New Member
Joined
Sep 6, 2020
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Hi to all!

My question regards a vba code.
How to conditional Formatting Shapes in a sheet?

I have a product list on sheet1
Many shapes on sheet 2, linked to every cell in sheet1 that contains that product name.
I need to color the background of every shape, if they contains the word for example "BETA".
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub liberovago()
   Dim Shp As Shape
   
   For Each Shp In Sheets("Sheet2").Shapes
      If InStr(1, Shp.TextFrame.Characters.Caption, "Beta", vbTextCompare) > 0 Then Shp.Fill.ForeColor.RGB = 45678
   Next Shp
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub liberovago()
   Dim Shp As Shape
  
   For Each Shp In Sheets("Sheet2").Shapes
      If InStr(1, Shp.TextFrame.Characters.Caption, "Beta", vbTextCompare) > 0 Then Shp.Fill.ForeColor.RGB = 45678
   Next Shp
End Sub
Thanks for the reply!

Unfortunately seems not functioning...

Runtime error 9. I've changed the name of the sheet (in italian "Foglio4" and the word that I'm looking for "Finocchi". Maybe it's just me and some mistake
screenshot.1.jpg
 
Upvote 0
You are trying to use the sheet codename, rather than the actual sheet name, so it should be
VBA Code:
For Each Shp In Foglio4.Shapes
 
Upvote 0
You are trying to use the sheet codename, rather than the actual sheet name, so it should be
VBA Code:
For Each Shp In Foglio4.Shapes
Yes, that's my error. But now the error is 1004.
screenshot.2.jpg


On another excel (test) file, your code is perfect.
 
Upvote 0
What is the actual error message?
 
Upvote 0
"valore specificato fuori dai valori previsti" means almost "specified value outside expected values"
 
Upvote 0
Maybe I've found something... In the sheet of the shapes, I've some shapes grouped. I've tried to ungrouped the shapes and the code works! Many thanks!!!
 
Upvote 0
Maybe I've found something... In the sheet of the shapes, I've some shapes grouped. I've tried to ungrouped the shapes and the code works! Many thanks!!!
But now I've another problem.. In this sheet I've also some little images, and a couple of 3d model.. How can I exclude these objects?
 
Upvote 0
Ok, how about
VBA Code:
Sub liberovago()
   Dim Shp As Shape
   
   For Each Shp In Foglio4.Shapes
      If Len(Shp.OLEFormat.Object.Formula) > 0 Then
         If InStr(1, Shp.TextFrame.Characters.Caption, "Finocchi", vbTextCompare) > 0 Then Shp.Fill.ForeColor.RGB = 45678
      End If
   Next Shp
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,914
Messages
6,181,713
Members
453,064
Latest member
robatthe2A

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