crazybumpbaby
New Member
- Joined
- Feb 28, 2012
- Messages
- 9
I have a VBA macro for Excel 2007 below that loops through a workbook and deletes a picture (shape) in a range at the top of each worksheet.
The macro works fine until a cell which contains a seemingly unrelated data validation list on Sheets(1) is changed. The macro then repeatedly trips up with a 'Run-time error 1004 - Application defined or object defined error'. Am somewhat out of ideas...
The cell with the data validation is outside of the range in which the shapes are deleted and does not set any of the variables in the macro.
Many thanks in advance for any advice.
Sub DeleteLogos()
Dim Count As Integer
Dim NumberOfWorksheets As Integer
Dim Logo As Shape
Dim LogoZone As Range
NumberOfWorksheets = Worksheets.Count
For Count = 1 To NumberOfWorksheets
With Sheets(Count)
Set LogoZone = .Range("A1:J7")
For Each Logo In .Shapes
If Not Application.Intersect(Logo.TopLeftCell, LogoZone) Is Nothing Then
If Logo.Type = msoPicture Then Logo.Delete
End If
Next Logo
End With
Next Count
End Sub
The macro works fine until a cell which contains a seemingly unrelated data validation list on Sheets(1) is changed. The macro then repeatedly trips up with a 'Run-time error 1004 - Application defined or object defined error'. Am somewhat out of ideas...
The cell with the data validation is outside of the range in which the shapes are deleted and does not set any of the variables in the macro.
Many thanks in advance for any advice.
Sub DeleteLogos()
Dim Count As Integer
Dim NumberOfWorksheets As Integer
Dim Logo As Shape
Dim LogoZone As Range
NumberOfWorksheets = Worksheets.Count
For Count = 1 To NumberOfWorksheets
With Sheets(Count)
Set LogoZone = .Range("A1:J7")
For Each Logo In .Shapes
If Not Application.Intersect(Logo.TopLeftCell, LogoZone) Is Nothing Then
If Logo.Type = msoPicture Then Logo.Delete
End If
Next Logo
End With
Next Count
End Sub