Help with an if error on excel vba

BORUCH

Well-known Member
Joined
Mar 1, 2016
Messages
528
Office Version
  1. 365
Platform
  1. Windows
hi

i have this piece of code in my excel macro.

Code:
ActiveSheet.Shapes.Range(Array("Picture 2")).Select

The problem i'm having is that sometimes depending on the sheet that i'm running the code on it can be "image1.png etc..

how can i modify this line that if it errors out it will select image1.png or image2.png

thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
if we're talking 2-3 options then this should do it:
Code:
...
On Error Resume Next
    Err.Clear
    ActiveSheet.Shapes.Range(Array("Picture 1")).Select
    If Err > 0 Then
        Err.Clear
        ActiveSheet.Shapes.Range(Array("Picture 2")).Select
        If Err > 0 Then
            Err.Clear
            ActiveSheet.Shapes.Range(Array("Picture 3")).Select
        End If
    End If
On Error GoTo 0
...
 
Upvote 0
With this you select the first image that exists on the sheet, no matter what its name.

Code:
    For Each shp In ActiveSheet.Shapes
        shp.Select
        Exit For
    Next
 
Upvote 0
Or if you really want to select all shapes:
Code:
ActiveSheet.Shapes.Selectall
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,867
Members
449,053
Latest member
Mesh

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