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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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