Select a Shape that Intersects (touches) a Cell (range) using VBA

michaelch2934

New Member
Joined
Sep 17, 2018
Messages
34
Using VBA code, I will be placing a shape somewhere within a large cell range. But FIRST I NEED TO REMOVE THE SHAPE that may already be there. I know the shape will intersect or touch a certain cell (G13). So, I need the code to simply select this shape and then, I can move it to another location on the sheet. Because there are other shapes on the same sheet, I can't do a general 'select all' command. Just the shape that intersects G13. Thanks in advance.
 
YES!!! This works very well for my intended purposes. Thank you so very much. Because I originally placed the shape 'over' G13, I know that by using G13 as the locus point, it will always 'find' the shape when it needs to be removed.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
YES!!! This works very well for my intended purposes. Thank you so very much. Because I originally placed the shape 'over' G13, I know that by using G13 as the locus point, it will always 'find' the shape when it needs to be removed.

Hi ​michaelch2934
If you would reply with a quote, we would know which piece of code worked for you.
Regards
Ravi Singh
 
Upvote 0
I have just reread your post and you wanted to MOVE not delete. oops :oops::oops:

Here is a code which
- counts how many shapes intersect cell G13
- selects a shape so that it can be moved

Code:
Sub IsThereAShapeToMove()
    Dim shp As Shape, shpRng As Range, c As Integer
    With ActiveSheet
        For Each shp In .Shapes
            Set shpRng = .Range(shp.TopLeftCell.Address, .Range(shp.BottomRightCell.Address))
            If Not Intersect(shpRng, .Range("G13")) Is Nothing Then
                c = c + 1: shp.Select
            End If
        Next shp
    End With
    If c > 1 Then MsgBox c & " intersecting shapes"
End Sub
This piece of code works very well for my intended purposes. Thanks to everyone who contributed to this posting.
 
Upvote 0
Hi ​michaelch2934
If you would reply with a quote, we would know which piece of code worked for you.
Regards
Ravi Singh

Sub IsThereAShapeToMove()
Dim shp As Shape, shpRng As Range, c As Integer
With ActiveSheet
For Each shp In .Shapes
Set shpRng = .Range(shp.TopLeftCell.Address, .Range(shp.BottomRightCell.Address))
If Not Intersect(shpRng, .Range("G13")) Is Nothing Then
c = c + 1: shp.Select
End If
Next shp
End With
If c > 1 Then MsgBox c & " intersecting shapes"
End Sub
This worked very well! Thank you all very much!!
 
Upvote 0

Forum statistics

Threads
1,217,381
Messages
6,136,228
Members
450,000
Latest member
jgp19

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