Solved

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

Posted on 2014-09-13
6
319 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 45

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 45

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 45

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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;…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

706 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

18 Experts available now in Live!

Get 1:1 Help Now