Delete photos from multiple worksheets within ranges using vba?

wai yan

New Member
Joined
Apr 20, 2019
Messages
7
Sub SelectAllPicturesInSelectedRange()


Dim oShape As shape
Dim rUserSel As Range

Sheet6.Range("E24:W204,AI1:BA204").Select


If TypeName(Selection) <> "Range" Then Exit Sub

Set rUserSel = Selection

For Each oShape In Sheet6.Shapes
If oShape.Type = msoPicture Then
If Not Intersect(oShape.TopLeftCell, rUserSel) Is Nothing Then
oShape.Select False
End If
End If
Next oShape

For Each oShape In Sheet7.Shapes
If oShape.Type = msoPicture Then
If Not Intersect(oShape.TopLeftCell, rUserSel) Is Nothing Then
oShape.Select False
End If
End If
Next oShape

End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
To select the object, you must first select the sheet.
To delete the object, change this: "oShape.Select False" for this: "oShape.Delete"


Code:
Sub SelectAllPicturesInSelectedRange()
    Dim oShape As Shape
    Dim rUserSel As Range
    
[COLOR=#0000ff]    Sheet6.Select[/COLOR]
[COLOR=#0000ff]    Set rUserSel = Range("E24:W204,AI1:BA204")[/COLOR]
    For Each oShape In Sheet6.Shapes
        If oShape.Type = msoPicture Then
            If Not Intersect(oShape.TopLeftCell, rUserSel) Is Nothing Then
                oShape.Select False
            End If
        End If
    Next oShape
        
[COLOR=#0000ff]    Sheet7.Select[/COLOR]
[COLOR=#0000ff]    Set rUserSel = Range("E24:W204,AI1:BA204")[/COLOR]
    Set oShape = Nothing
    For Each oShape In Sheet7.Shapes
        If oShape.Type = msoPicture Then
            If Not Intersect(oShape.TopLeftCell, rUserSel) Is Nothing Then
                oShape.Select False
            End If
        End If
    Next oShape
End Sub
 
Upvote 0
To select the object, you must first select the sheet.
To delete the object, change this: "oShape.Select False" for this: "oShape.Delete"


Code:
Sub SelectAllPicturesInSelectedRange()
    Dim oShape As Shape
    Dim rUserSel As Range
    
[COLOR=#0000ff]    Sheet6.Select[/COLOR]
[COLOR=#0000ff]    Set rUserSel = Range("E24:W204,AI1:BA204")[/COLOR]
    For Each oShape In Sheet6.Shapes
        If oShape.Type = msoPicture Then
            If Not Intersect(oShape.TopLeftCell, rUserSel) Is Nothing Then
                oShape.Select False
            End If
        End If
    Next oShape
        
[COLOR=#0000ff]    Sheet7.Select[/COLOR]
[COLOR=#0000ff]    Set rUserSel = Range("E24:W204,AI1:BA204")[/COLOR]
    Set oShape = Nothing
    For Each oShape In Sheet7.Shapes
        If oShape.Type = msoPicture Then
            If Not Intersect(oShape.TopLeftCell, rUserSel) Is Nothing Then
                oShape.Select False
            End If
        End If
    Next oShape
End Sub


It is perfectly work bro. I really aprreciate for it. !!!
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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