Moonbeam111
Board Regular
- Joined
- Sep 24, 2018
- Messages
- 73
- Office Version
- 365
- 2010
I'm trying to delete pictures in range J22:J25 except for the picture named "ZC_Pic". Here's the code I was using. It works but it deletes ZC_Pic.
If I change my code to this:
I get a type mismatch error and/or application, object defined error here: For Each xpic In xRg . I don't quite understand why.
I have another question. Is there a quick and dirty way to insert a column and then use the find/replace in VBA to make every range reference one column further? For example, if my ranges were all in B and C and D. And I inserted a column, could I use a find/replace (possibly using pattern searching) to have each macro that was B,C,D now reference C,D,E?
VBA Code:
Set xRg = Range("J22:J25")
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
If I change my code to this:
VBA Code:
Dim xpic As Picture
Set xRg = Range("J22:J25")
For Each xpic In xRg
If xpic <> "ZC_Pic" Then
xpic.Delete
End If
Next xpic
I get a type mismatch error and/or application, object defined error here: For Each xpic In xRg . I don't quite understand why.
I have another question. Is there a quick and dirty way to insert a column and then use the find/replace in VBA to make every range reference one column further? For example, if my ranges were all in B and C and D. And I inserted a column, could I use a find/replace (possibly using pattern searching) to have each macro that was B,C,D now reference C,D,E?