VBA | Select if function with shapes

Huber

New Member
Joined
Jan 17, 2023
Messages
2
Hi all,

I'm seeking a solution to the following problem:

There is a Swiss country map on a post code basis (hundreds of shapes) on the excel sheet in question (see image attached). There are two groups. Group 1 of post codes is colored blue. Group 2 of post codes is colored green. I want to change the color of the shapes colored green to grey.

Formulated pragmatically I imagine the following steps in VBA:

(1) Select all shapes of the worksheet colored green
(2) Change color of selected shapes to gray

My question: Does anyone know how to code this? Or of an alternative solution?

Thanks for any help!

Best,
Marc
 

Attachments

  • Swiss Map.JPG
    Swiss Map.JPG
    77.5 KB · Views: 16

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Do this on a copy of the sheet or workbook to test.
Suggest, first find the name of one shape that you want to change. Then run this from a standard module and substitute your sheet name and the Name of that shape:

VBA Code:
Sub shapeName()
Dim shp As Shape

For Each shp In Sheets("4").Shapes
   If shp.Name = "aNameHere" Then Debug.Print shp.Fill.BackColor
Next

End Sub
Now you know the colour that you want to change. Suppose that is 16777215. Now colour that shape as you wish and run that again. Now you know the colour you want to change to. Then in that same module have
VBA Code:
Sub shapeColour()
Dim shp As Shape

For Each shp In Sheets("4").Shapes
     If  shp.Fill.BackColor = oldColourNumber Then shp.Fill.BackColor = NewColourNumber
Next

End Sub
 
Upvote 0
Do this on a copy of the sheet or workbook to test.
Suggest, first find the name of one shape that you want to change. Then run this from a standard module and substitute your sheet name and the Name of that shape:

VBA Code:
Sub shapeName()
Dim shp As Shape

For Each shp In Sheets("4").Shapes
   If shp.Name = "aNameHere" Then Debug.Print shp.Fill.BackColor
Next

End Sub
Now you know the colour that you want to change. Suppose that is 16777215. Now colour that shape as you wish and run that again. Now you know the colour you want to change to. Then in that same module have
VBA Code:
Sub shapeColour()
Dim shp As Shape

For Each shp In Sheets("4").Shapes
     If  shp.Fill.BackColor = oldColourNumber Then shp.Fill.BackColor = NewColourNumber
Next

End Sub
Thank you!
 

Attachments

  • Swiss Map.JPG
    Swiss Map.JPG
    190.1 KB · Views: 7
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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