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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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