Macro to Select All Shapes in a Specific Range

ndouglas48

New Member
Joined
Sep 13, 2012
Messages
29
Hello all! I am trying to create a macro that simply selects all shapes in a specific range, let's say A1:D5. I am able to select all shapes in a given worksheet but need to narrow this to the specific range. Here's the kicker: How can I do this without referencing the specific shape names, i.e. "Oval 4"? I am using macros to create and delete shapes so the names continually change. So this macro needs to search the range and select all shapes that are present within it. Any help is hugely appreciated. Thank you!

ND
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hello all! I am trying to create a macro that simply selects all shapes in a specific range, let's say A1:D5. I am able to select all shapes in a given worksheet but need to narrow this to the specific range. Here's the kicker: How can I do this without referencing the specific shape names, i.e. "Oval 4"? I am using macros to create and delete shapes so the names continually change. So this macro needs to search the range and select all shapes that are present within it. Any help is hugely appreciated. Thank you!

ND

Since shapes are not properties of the Range object, the task will be quite difficult. Usually shapes are handled as separate entities when manipulating, coloring, and sizing.
 
Upvote 0
Hello all! I am trying to create a macro that simply selects all shapes in a specific range, let's say A1:D5.
Do the shapes have to be wholly contained within the range, or will just intersecting them be okay?
 
Upvote 0
I believe just intersecting them would be okay. I have the following vba that does this but it deletes the shapes. Not sure if there is a way to change this so it just selects them instead of deleting.

Dim shp As Shape


For Each shp In ActiveSheet.Shapes

If Not Intersect(shp.TopLeftCell, Range("A1:D5")) Is Nothing Then

shp.Delete
End If
Next shp
Range("A1").Select
 
Upvote 0
Hi

Can you tell us what you need to do? It's not usually necessary to select objects in vba.

For ex., in the code you posted you can see that no shape is selected and you do what you need to do.
 
Upvote 0
I am wanting to create an area where someone could draw using excel shapes and can easily select all objects that are drawn in that area without having to manually click on each one. The drawing area is rather large and because shapes will always be different I cannot rely on using specific names to identify these shapes, i.e. "Oval 1".
 
Upvote 0
Try for the active sheet:

Code:
Sub SelectShapes()
Dim shp As Shape
Dim r As Range

Set r = Range("A1:D5")

For Each shp In ActiveSheet.Shapes
    If Not Intersect(Range(shp.TopLeftCell, shp.BottomRightCell), r) Is Nothing Then _
        shp.Select Replace:=False
Next shp
End Sub
 
Upvote 0
Is there something I could add to this that would automatically group these selected objects after selection?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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