Need help resolving an inconsistent runtime 1004 error when deleting pictures.

karamarrott

New Member
Joined
Jan 26, 2023
Messages
5
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a report that needs pictures imported regularly. I have a Macro that will delete the pictures in a column and then import new ones. However, using the button back to back will eventually give an error of "1004 Unable to get TOPLEFTCELL properly of picture class."

Is there a way to rewrite the picture delete VBA or some kind of error in the code?
VBA Code:
Set xRg = Range("AZ3:AZ14")
    For Each xPic In ActiveSheet.Pictures
    
        Set xPicRg = Range(xPic.TopLeftCell.Address & ":" & xPic.BottomRightCell.Address)
        If Not Intersect(xRg, xPicRg) Is Nothing Then xPic.Delete
        Next
On Error Resume Next

Also I have version 2019 while others that use the file have 365 could this cause an issue?

Thank you
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi karamarrott and Welcome to the Board. You can trial this code. Please keep a backup copy of your wb before trialing. Adjust the sheet name to suit. HTH. Dave
Code:
Dim Sh As Shape
With Sheets("Sheet1")
For Each Sh In .Shapes
If Application.Version > 12 Then
If Sh.Type = 11 Then
Sh.Delete
End If
Else
If Sh.Type = 13 Then
Sh.Delete
End If
End If
Next Sh
End With
 
Upvote 0
Hi karamarrott and Welcome to the Board. You can trial this code. Please keep a backup copy of your wb before trialing. Adjust the sheet name to suit. HTH. Dave
Code:
Dim Sh As Shape
With Sheets("Sheet1")
For Each Sh In .Shapes
If Application.Version > 12 Then
If Sh.Type = 11 Then
Sh.Delete
End If
Else
If Sh.Type = 13 Then
Sh.Delete
End If
End If
Next Sh
End With
Yes, that worked nice, however, can I make it specific to a range on that sheet?
 
Upvote 0
I'm not sure... I have never tried. Maybe trial...
Code:
With Sheets("Sheet1").Range("AZ3:AZ14")
I'd be interested to know the outcome. Dave
 
Upvote 0
I'm not sure... I have never tried. Maybe trial...
Code:
With Sheets("Sheet1").Range("AZ3:AZ14")
I'd be interested to know the outcome. Dave
Yes, I did try that actually, and i get a
1674784704270.png
1674784741415.png
 
Upvote 0
Nothings ever easy. Maybe..
Code:
Dim Sh As Shape
With Sheets("Sheet1")
For Each Sh In .Shapes
If Not Application.Intersect(Sh.TopLeftCell, .Range("AZ3:AZ14")) Is Nothing Then
    If Application.Version > 12 Then
        If Sh.Type = 11 Then
        Sh.Delete
        End If
    Else
        If Sh.Type = 13 Then
        Sh.Delete
        End If
    End If
End If
Next Sh
End With
Dave
 
Upvote 0
Solution
Nothings ever easy. Maybe..
Code:
Dim Sh As Shape
With Sheets("Sheet1")
For Each Sh In .Shapes
If Not Application.Intersect(Sh.TopLeftCell, .Range("AZ3:AZ14")) Is Nothing Then
    If Application.Version > 12 Then
        If Sh.Type = 11 Then
        Sh.Delete
        End If
    Else
        If Sh.Type = 13 Then
        Sh.Delete
        End If
    End If
End If
Next Sh
End With
Dave
Oh, you are the best! I was trying to put those together and just couldn't get it right. But yours worked perfectly!! thank you!
 
Upvote 0
Oh, you are the best! I was trying to put those together and just couldn't get it right. But yours worked perfectly!! thank you!
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,128
Members
453,021
Latest member
Justyna P

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