Reputation: 1010
I want to delete different image (I copy image to this cell, using VBA code, so each image have another name), on merged cells (I don't want to unmarged cells). On this worksheet I have another images, so I can't use code like this:
ActiveSheet.Shapes.SelectAll
Selection.Delete
Upvotes: 1
Views: 573
Reputation: 35853
Try this code (Q related to this):
Sub deletePicturesFromMergedCells()
Dim sh As Shape, ws As Worksheet
Dim rng As Range
Set ws = Worksheets("character")
For Each sh In ws.Shapes
'if shape is picture
If sh.Type = msoPicture Or sh.Type = msoLinkedPicture Then
'get entire range where picture placed
Set rng = ws.Range(sh.TopLeftCell, sh.BottomRightCell)
'if picture is in range A8 (with megred cells) then delete it
If Not Intersect(rng, ws.Range("A8").MergeArea) Is Nothing Then
sh.Delete
End If
End If
Next sh
End Sub
Upvotes: 2