LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Mysterious Error 1004 caused by AutoFilter?

I responded to Mihai's Compare shapes for obtaining a value post
concerning how to get a value into a cell based on the Shape in that
cell.

Mihai discovered that my suggested code (see code below) resulted in
Error 1004 if AutoFilter was turned on, otherwise it worked perfectly.
The offending code lines are "If Not Intersect(Shp.TopLeftCell,
rngShpVal) Is Nothing Then" and "Shp.TopLeftCell.Value = M", the
only lines referring to "Shp.TopLeftCell" which is causing the
error.

I have used "On Error Resume Next" just before the "For Each
Shp" loop to bypass the error message.

There are two things I don't understand:

1. Why would simply having AutoFilter just turned on, and not actually
doing any filtering (ie Show All) cause the error, and

2. Why is bypassing the error message enough to have my code work
properly, I would have expected the error to cause my code to fail.

I'm glad the code is working but I'd really like to know the inside
story behind the problem.
Any ideas?

Public Sub ShapeCellValue()
Dim Shp As Shape
Dim rngShpVal As Range
Dim J As Byte
Dim M As Byte
'Change Range("C3:F11") to suit your needs
'Grouped shapes outside this range are ignored
Set rngShpVal = _
ActiveSheet.Range("C3:F11")
rngShpVal.ClearContents
On Error Resume Next '<<<< solved problem
For Each Shp In ActiveSheet.Shapes
M = 1
If Not Intersect(Shp.TopLeftCell, rngShpVal) _
Is Nothing Then
If Shp.Type = msoGroup Then
For J = 1 To Shp.GroupItems.Count
If Shp.GroupItems(J).Fill.Visible = True Then
If Shp.GroupItems(J).Fill.ForeColor. _
SchemeColor = 8 Then Let M = M + 1
End If
Next J
End If
Shp.TopLeftCell.Value = M
End If
Next Shp
End Sub

Ken Johnson

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sumproduct error caused by too many curly brackets? Romileyrunner1 Excel Worksheet Functions 7 September 4th 09 11:12 AM
Macro runtime error 1004 with Autofilter Lorna B Excel Discussion (Misc queries) 3 May 25th 07 08:38 PM
Error caused by *.xls file WLMPilot Excel Discussion (Misc queries) 0 July 27th 06 03:09 PM
Type mismatch mysterious error BillyJ Excel Discussion (Misc queries) 3 October 28th 05 01:28 AM
Error 1004 update autofilter and pivottable fonz Excel Programming 1 October 12th 04 02:59 PM


All times are GMT +1. The time now is 02:39 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"