Delete shapes when not Picture 1

satkin2

New Member
Joined
Oct 22, 2009
Messages
25
Hi,
I've got a spreadsheet with a macro that loops through the worksheets pasting a row 4 times. The row has an image in it.

When I run the first time on the template it puts new images in. If I run it again it pastes another image in there on top of the previous one. I'd like to be able to delete my shapes/pictures prior to the paste. The only image I want to keep is Picture 1 (the one I copy).

Is there a way to delete all images but one, or delete images if name isn't 'Picture 1'?

Many thanks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
After some trial and error I think i've sorted it...
Code:
Dim wbBook As Workbook
  Dim wbSheet As Worksheet
  
  Dim shp As Shape
  
  Set wbBook = ActiveWorkbook
  
  For Each wsSheet In wbBook.Worksheets
    wsSheet.Activate
    
    For Each shp In wsSheet.Shapes
      If wsSheet.Name = "Format" Then
        If shp.Name <> "Picture 1" Then
          shp.Delete
        End If
      ElseIf wsSheet.Name <> "Format" Then
        shp.Delete
      End If
    Next
  Next wsSheet
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,310
Members
452,906
Latest member
phanmemchatdakenhupviral

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