I received some nice code from Alex Blakenburg that allows me to delete all shapes above row 5 in my workbook. I now also want to delete all pictures above row 5 as well. So I took the original code for shapes and tried to do the same for pictures using a variable I named pic. My code is shown below.
However, the code creates a Type Mismatch error when it comes to the line - For Each pic In ws.Pictures
I would appreciate any help in correcting the code.
Thanks
However, the code creates a Type Mismatch error when it comes to the line - For Each pic In ws.Pictures
I would appreciate any help in correcting the code.
Thanks
VBA Code:
Private Sub Delete_Shapes_and_Pictures()
Dim ws As Worksheet
Dim shp As Shape
Dim pic As Picture
For Each ws In ThisWorkbook.Worksheets
For Each shp In ws.Shapes
If shp.Type = msoAutoShape And shp.BottomRightCell.Row < 5 Then shp.Delete
Next shp
For Each pic In ws.Pictures
If pic.Type = msoPicture And pic.BottomRightCell.Row < 5 Then pic.Delete
Next pic
Next ws
End Sub