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.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hi - could record macro & select the shape, code will then tell you what you the name
 
Upvote 0
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).
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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
Back
Top