Delete Pictures within a range VBA

borski88

Board Regular
Joined
Jul 3, 2015
Messages
71
Code:
Sub ClearData()
Dim Pic As Object
  'Clears Data for Name, Login, Badge Number, etc
  
    Range( _
        "K2:N3,D2:G3,D9:G10,K9:N10,D16:G17,K16:N17,K23:N24,D23:G24" _
        ).ClearContents
    
    'Deletes Pictures from file
    
    For Each Pic In ActiveSheet.Pictures
    Pic.Delete
    Next Pic

End Sub

Is there a way to only delete pictures within A1:O30?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try...

Code:
    For Each Pic In ActiveSheet.Pictures
        If Not Intersect(Pic.TopLeftCell, Range("A1:O30")) Is Nothing Then
            Pic.Delete
        End If
    Next Pic

By the way, 'Pic" can be declared as Picture. Then you'll also have available the Inteli-Sense.

Hope this helps!
 
Upvote 0
Try...

Code:
    For Each Pic In ActiveSheet.Pictures
        If Not Intersect(Pic.TopLeftCell, Range("A1:O30")) Is Nothing Then
            Pic.Delete
        End If
    Next Pic

By the way, 'Pic" can be declared as Picture. Then you'll also have available the Inteli-Sense.

Hope this helps!

Thank you, it worked perfectly!
 
Upvote 0
Hi

i Tried the exact code and it does nothing for me. idk if its because of my image format (GIF)

Sheets("Print PG").Select
Dim pic As Picture
For Each pic In ActiveSheet.Pictures
If Not Intersect(pic.TopLeftCell, Range("A85:K101")) Is Nothing Then
pic.Delete
End If
 
Upvote 0
Hi

i Tried the exact code and it does nothing for me. idk if its because of my image format (GIF)

Sheets("Print PG").Select
Dim pic As Picture
For Each pic In ActiveSheet.Pictures
If Not Intersect(pic.TopLeftCell, Range("A85:K101")) Is Nothing Then
pic.Delete
End If

The top left corner of the image cannot extend beyond the top or left side of the target range. To allow this to happen, try...

Code:
If Not Intersect([COLOR=#FF0000]Range(pic.TopLeftCell, pic.BottomRightCell)[/COLOR], Range("A85:K101")) Is Nothing Then
 
Upvote 0
Can you please confirm exactly what it is you're trying to do?


I have a daily report were I need to delete and replace the pic image within Range("A85:K101"). There are other images within the sheet I have to keep.

regards
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,025
Members
449,060
Latest member
LinusJE

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