VBA - manipulate Collection of shapes

D4rwin

Board Regular
Joined
Mar 31, 2014
Messages
91
Hi,
I have a sheet with several shapes (100+) and I need to manipulate the transparency of each shape based on the text in each shape.
Currently I am using a For Loop to go through each shape to test if the text equals a specific string. If so, the shape transparency is modified.
However, I suspect that this is quite a cumbersome operation for VBA as it takes a few seconds to process each shape during the loop. I am wondering if it: a) is possible to add each shape matching the text criteria to a collection, and b) is possible to manipulate the shape transparency of each shape in the collection in order to speed it up.

Eventhough the following code will not work, it demonstrates what I'm trying to achieve:

Code:
dim shp as shape
dim colShapes as new collection

for each shp in activesheet.shapes
     if shp.textframe2.textrange.text = "string" then
          colShapes.add shp
     end if
next shp

colShapes.fill.transparency = 0.8

Again, the purpose is to speed up the processing time so that VBA will apply the transparency modification in one sweep.
All suggestions/comments are welcome.
Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,627
Messages
5,838,440
Members
430,548
Latest member
hh_dh2001

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
Top