Shape Array TopLeftCell.Address

ldarley

Board Regular
Joined
Apr 10, 2012
Messages
82
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!
 

jasonb75

Well-known Member
Joined
Dec 30, 2008
Messages
7,154
Office Version
2019
Platform
Windows
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.
 

ldarley

Board Regular
Joined
Apr 10, 2012
Messages
82
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.
 

Forum statistics

Threads
1,082,316
Messages
5,364,483
Members
400,802
Latest member
RichBRich

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top