Knowing Name of Shape with VBA

prajul89

Active Member
Joined
Jul 9, 2011
Messages
404
Hi,
How to know the name of the Shapes (Rectangle) in a particular range with macro.
 

Some videos you may like

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Dannyh1

Well-known Member
Joined
Nov 18, 2009
Messages
1,144
Hi - could record macro & select the shape, code will then tell you what you the name
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,686
Office Version
  1. 2010
Platform
  1. Windows
Not exactly sure what you are after, but see if you can make use of one of these (see the macro's name)...

Code:
Sub GetShapesWhoseSurroundingRectangleTouchesTheSelectedRangeSomewhere()
  Dim SH As Shape, ShapesInRange As String
  For Each SH In ActiveSheet.Shapes
    If Not Intersect(Range(SH.TopLeftCell.Address & ":" & SH.BottomRightCell.Address), Selection) Is Nothing Then
      ShapesInRange = ShapesInRange & SH.Name & vbLf
    End If
  Next
  If Len(ShapesInRange) Then
    MsgBox ShapesInRange
  Else
    MsgBox "There are no shapes in that range!"
  End If
End Sub
 
Sub GetShapesThatAreCompletelyWithinTheSelectedRangeOfCells()
  Dim SH As Shape, ShapesInRange As String, Intersection As Range
  For Each SH In ActiveSheet.Shapes
    Set Intersection = Intersect(Range(SH.TopLeftCell.Address & ":" & SH.BottomRightCell.Address), Selection)
    If Not Intersection Is Nothing Then
      If Intersection.Address = Range(SH.TopLeftCell.Address & ":" & SH.BottomRightCell.Address).Address Then
        ShapesInRange = ShapesInRange & SH.Name & vbLf
      End If
    End If
  Next
  If Len(ShapesInRange) Then
    MsgBox ShapesInRange
  Else
    MsgBox "There are no shapes in that range!"
  End If
End Sub
Note that each macro will list all the shapes that meet the condition the macro is looking for (again, read each macro's name to see what that is).
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,779
Office Version
  1. 2010
Platform
  1. Windows
One way:

Code:
Sub x()
    Dim shp As Shape
    
    For Each shp In ActiveSheet.Shapes
        If Not Intersect(shp.TopLeftCell, Range("A1:A10")) Is Nothing Then
            shp.Select
            MsgBox shp.Name
        End If
    Next shp
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,608
Messages
5,597,143
Members
414,129
Latest member
mr vba

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top