Excel – remove images from an Excel spreadsheet by name

microsoft excelvba

I have a series of large Microsoft Excel 2010 spreadsheets with images in them, and I need to remove 2/3 of those images. All the images I need to remove contain the same string of characters in the title, "Err". The images I need to keep do not contain that string of characters.

Is there a way to find and delete images by partial name?

Best Answer

Taking your criteria literally "Err" in the picture name. If you want to extend this to include "err" then convert the picture name to upper or lowercase and search for that with InStr.

Sub deleteErrPics()
 For Each pic In ActiveSheet.Shapes
 If InStr(1, pic.Name, "Err") <> 0 Then pic.Delete
 Next pic
End Sub