We help IT Professionals succeed at work.

An excel cell 'contains' a jpg shape. When I duplicate that cell how do I get the shape name for the newly duplicated shape?

Kelvin4
Kelvin4 asked
on
My Worksheet contains a row of cells in which different shapes have been added to some (not all)  specific columns. (Their purpose is that clicking each shape provides access to different vba procedures).

Some cells in the row contain comments, but cells with an added shapes do NOT contain comments

Shapes are added via excel Shapes.AddPicture Method

When a Shape is added to a cell, Shape.name (eg 'Picture16') is recorded to enable control of visibility, and shape deletion.

Now I copy the row of shapes to a new row on the same sheet. How do I enumerate the shapes collection to obtain the shape.names for each identified cell that contains a newly copied shape?

Thanks
Kelvin
Comment
Watch Question

Top Expert 2016
Commented:
Hi,

pls try

Sub Macro()
Set newRow = Range("4:4")
For Each shp In ActiveSheet.Shapes
    If Not Intersect(newRow, shp.TopLeftCell) Is Nothing Then
        MsgBox shp.Name
    End If
Next
End Sub

Open in new window

Regards

Author

Commented:
Thanks, Rgonzo:
I'll work on this by tomorrow
Kelvin
Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
If you are interested in the name of the last shape added you don't need to iterate through them but rather just do something like LastShapeName = ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Name.

Author

Commented:
Thanks for rapidly and completely solving my question, and for taking the trouble to expand my knowledge.
Regards, Kelvin
Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014