Shape Array TopLeftCell.Address

ldarley

Board Regular
Joined
Apr 10, 2012
Messages
106
Office Version
  1. 2019
  2. 2016
Hi

I working with a series of shapes on a worksheet where I am holding the shape data in a array and then writing each shapes TopLeftCell.Address into another worksheet to do some calculations. The problem is the For loop is slow due to the number of iterations it has to go through.

The relevant part of the code looks like this:

Code:
'set up shape array

ReDim shape_index(1 To x)
For i = 1 To x
    shape_index(i) = i
Next


Set shprng = Sheet2.Shapes.Range(shape_index)

'write shape address to Sheet1

For i = 1 To x
     y = i + 1
     Sheet1.Cells(y, 5) = shprng(i).TopLeftCell.Address
Next

Is there a quick way or me to take all the TopLeftCell.Address data for each shape in the array and place that information into the other worksheet in one go or to I have to iterate through each shape and do that individually?

Any thoughts is greatly appreciated!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I suspect that this method might be slower, but might be worth comparing.
Code:
For i = 1 To x
     Sheet1.Cells(x + 1, 5) = Sheet2.Shapes(i).TopLeftCell.Address
Next
Are you using Screeupdating = False, Calculation = xlManual, etc. with your code? They can make a difference.
 
Upvote 0
thanks Jason yes I have everything disabled page breaks the lot,i'll give your suggestion a try.

This is a small section of my code without this section it runs in a couple of seconds, however with it, for around 300 shapes its takes about a minute and a half, which feels like an age.
 
Upvote 0

Forum statistics

Threads
1,223,939
Messages
6,175,533
Members
452,652
Latest member
eduedu

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