Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-09-13
6
355 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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 Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

856 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