Solved

Excel 2010: Selecting shapes by name not id when names are numbers

Posted on 2014-09-13
6
333 Views
Last Modified: 2014-09-16
My client has a worksheet with a list shape names in column A. The rest of the worksheet has varying shapes that match the names in column A. The problem is that all of his shape names are numbers from 1 to 1000. This means when I use something like: "activesheet.shapes("128").select" the shape with the id of 128 will be selected instead of the shape with the name of "128". Is there a way to select a shape based on the name only?

Below is a small snippet of code that will select each shape that exists in column A. Any way to adjust this to select shapes by the name instead of the id?

x=1
Do

activesheet.shapes(activesheet.cells(x,1)).select

x=x+1
Loop while (x<250)
0
Comment
Question by:ouestque
  • 4
6 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40320881
That does not happen when I do it.

I created several shapes and then named them with out of order numbers. The when I did this

ActiveSheet.Shapes("2").Select

Open in new window


followed by this

ActiveSheet.Shapes(2).Select

Open in new window


different shapes were selected.
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 334 total points
ID: 40320886
Oh, I see! Do this instead.

activesheet.shapes(activesheet.cells(x,1).Text).select
0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 334 total points
ID: 40320890
You also might consider changing your loop to this


For x = 1 To 250

activesheet.shapes(activesheet.cells(x,1).Text).select

Next

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 166 total points
ID: 40321080
As an alternate method, you could consider using the For...Each method to select all shapes in a sheet like so:
Sub Edit_Shapes()
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
        'Test or process the shape object
        'Use shp. to control the shape object for example
        'MsgBox shp.Name
        Next shp
End Sub

Open in new window


This way, you don't have to know the names of each shape, nor do you need to know how many there are on each sheet.

Regards,
-Glenn
0
 

Author Closing Comment

by:ouestque
ID: 40325208
Awesome. Thanks!!!
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40325382
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now