PC Review


Reply
Thread Tools Rate Thread

Autofilter or SpecialCells-related bug?

 
 
G Lykos
Guest
Posts: n/a
 
      15th Aug 2007
Greetings! Have run into an apparent glitch, would appreciate any ideas.

Briefly:
1. Selection.AutoFilter Field:=2, Criteria1:="Test" ' isolate rows of
interest using an autofilter
2. Range("B1").Offset(1).Select ' select first data cell below header cell
3. Range(Selection,
Selection.End(xlDown)).SpecialCells(xlCellTypeVisible).Select ' select
filtered cells
4. Set Config = Selection ' assign handle to the range collection

Up to here, everything is okay, sort of. If there is at least one visible
row in the filtered list, then Config.count accurately reflects the number
of autofiltered rows (cells, actually), and Config can be used as a
collection for subsequent processing.

HOWEVER, if there are no filtered cells (meaning no data row is visible in
the autofilter), then Config.count is not zero but rather is some large
number (less than total number of rows in data set).

Q1: What is it doing? Is this somehow self-inflicted?
Q2: As a work-around, what are options to identify what should be an empty
collection?

Office 2003 with all updates.

Thanks!
George


 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      15th Aug 2007
Hi George,

No glitch. Manually replicate your scenario, with B3 selected in the hidden
cell, Ctrl-Shift End down-arrow, F5 > Special > Visible cells.
You will end up with all cells in col-B below your filter range selected
with a large row count

For ideas -
Sub test2()
Dim rng As Range
If ActiveSheet.AutoFilterMode Then
' change 1 to column within the Filter range of interest
Set rng = ActiveSheet.AutoFilter.Range.Columns(1)
Set rng = rng(1).Offset(1).Resize(rng.Rows.Count - 1)

On Error Resume Next
Set rng = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "no visible cells in filter range"
Else
MsgBox rng.Rows.Count
End If
End If
End Sub

If your filter range is +16k rows, SpecialCells might fail if every other
row is invisible and trying to return more than 8192 non-contiguous ares of
cells. Workaround if necessary.

Regards,
Peter T


"G Lykos" <(E-Mail Removed)> wrote in message
news:#6J$(E-Mail Removed)...
> Greetings! Have run into an apparent glitch, would appreciate any ideas.
>
> Briefly:
> 1. Selection.AutoFilter Field:=2, Criteria1:="Test" ' isolate rows of
> interest using an autofilter
> 2. Range("B1").Offset(1).Select ' select first data cell below header

cell
> 3. Range(Selection,
> Selection.End(xlDown)).SpecialCells(xlCellTypeVisible).Select ' select
> filtered cells
> 4. Set Config = Selection ' assign handle to the range collection
>
> Up to here, everything is okay, sort of. If there is at least one visible
> row in the filtered list, then Config.count accurately reflects the number
> of autofiltered rows (cells, actually), and Config can be used as a
> collection for subsequent processing.
>
> HOWEVER, if there are no filtered cells (meaning no data row is visible in
> the autofilter), then Config.count is not zero but rather is some large
> number (less than total number of rows in data set).
>
> Q1: What is it doing? Is this somehow self-inflicted?
> Q2: As a work-around, what are options to identify what should be an

empty
> collection?
>
> Office 2003 with all updates.
>
> Thanks!
> George
>
>



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      15th Aug 2007
here's what i've done in the past. lest say my range is a5:s8932.
i use these statements to determine the first and last row
fRow = range("A5:s8932").CurrentRegion.Offset(1,
0).SpecialCells(xlCellTypeVisible).Row
lRow = range("A5:s8932").CurrentRegion.SpecialCells(xlCellTypeLastCell).Row

then, if the first row = 5, i know there are no records, because it's the header
row.


--


Gary


"G Lykos" <(E-Mail Removed)> wrote in message
news:%236J$(E-Mail Removed)...
> Greetings! Have run into an apparent glitch, would appreciate any ideas.
>
> Briefly:
> 1. Selection.AutoFilter Field:=2, Criteria1:="Test" ' isolate rows of
> interest using an autofilter
> 2. Range("B1").Offset(1).Select ' select first data cell below header cell
> 3. Range(Selection,
> Selection.End(xlDown)).SpecialCells(xlCellTypeVisible).Select ' select
> filtered cells
> 4. Set Config = Selection ' assign handle to the range collection
>
> Up to here, everything is okay, sort of. If there is at least one visible
> row in the filtered list, then Config.count accurately reflects the number
> of autofiltered rows (cells, actually), and Config can be used as a
> collection for subsequent processing.
>
> HOWEVER, if there are no filtered cells (meaning no data row is visible in
> the autofilter), then Config.count is not zero but rather is some large
> number (less than total number of rows in data set).
>
> Q1: What is it doing? Is this somehow self-inflicted?
> Q2: As a work-around, what are options to identify what should be an empty
> collection?
>
> Office 2003 with all updates.
>
> Thanks!
> George
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel 2007 autofilter change to 2003 autofilter functionality? jonnybrovo815 Microsoft Excel Misc 1 19th Apr 2010 10:05 PM
2007 excel autofilter back to 2003 autofilter? jonnybrovo815 Microsoft Excel Misc 3 19th Apr 2010 08:11 PM
2007 excel autofilter change back to 2003 autofilter? jonnybrovo815 Microsoft Excel Misc 1 19th Apr 2010 05:53 PM
VB Question - AutoFilter related - 'Criteria1:' secion of my code Midnight Microsoft Excel Programming 6 13th Aug 2007 05:17 PM
AutoFilter /specialcells Ron de Bruin Microsoft Excel Programming 8 13th Jan 2004 03:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 AM.