Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Filter and count hidden cells problem

Excel XP & Win XP
I have headers in row 2.
I have data in row 3 only, therefore, RngToCopy is B3. This is correct.
I invoke an Auto-Filter on the data and, as a result, there are NO visible
rows (below the header row).
I have the following 2 message boxes:
MsgBox RngToCopy.Address(0, 0)
MsgBox RngToCopy.SpecialCells(xlCellTypeVisible).Count
The first MsgBox gives B3. Correct.
The second MsgBox gives 16776960 which is very close to the number of cells
in the sheet!!.
Since B3 is the RngToCopy and B3 is hidden (by filter), I expected the
second MsgBox to give a zero.
How can I get the count of visible cells in a range if all the cells in the
range are hidden?
Or, to put it another way, how can I determine that no rows satisfied the
filter criteria?
Thanks for your time. Otto


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Filter and count hidden cells problem

Try this on a test worksheet:

Select A1:E20
type asdf
and hit ctrl-enter to fill those 100 cells
select B3
Hide row 3
Edit|goto|special|visible cells only

What's selected?

The same thing happens in code.

Using .specialcells with a single cell can give you unwanted results.

And the same kind of thing can happen when you do Edit|replace. If only one
cell is selected, the whole sheet (visible cells only) are affected.

So you'll want to make sure that the number of rows visible after the filter is
bigger than 0.

One way:

With activesheet.AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible). Count = 1 Then
MsgBox "only the headers are visible"
else
'resize to avoid the header
'and come down one row
Set VisRng = .Resize(.Rows.Count - 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With


Otto Moehrbach wrote:

Excel XP & Win XP
I have headers in row 2.
I have data in row 3 only, therefore, RngToCopy is B3. This is correct.
I invoke an Auto-Filter on the data and, as a result, there are NO visible
rows (below the header row).
I have the following 2 message boxes:
MsgBox RngToCopy.Address(0, 0)
MsgBox RngToCopy.SpecialCells(xlCellTypeVisible).Count
The first MsgBox gives B3. Correct.
The second MsgBox gives 16776960 which is very close to the number of cells
in the sheet!!.
Since B3 is the RngToCopy and B3 is hidden (by filter), I expected the
second MsgBox to give a zero.
How can I get the count of visible cells in a range if all the cells in the
range are hidden?
Or, to put it another way, how can I determine that no rows satisfied the
filter criteria?
Thanks for your time. Otto


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Filter and count hidden cells problem

Dave
Thanks for taking the time to explain that. I understand now what was
happening. I'll incorporate your code to test for visible rows including
the headers and will bypass the meat of the code if it's only 1. Thanks
again. Otto
"Dave Peterson" wrote in message
...
Try this on a test worksheet:

Select A1:E20
type asdf
and hit ctrl-enter to fill those 100 cells
select B3
Hide row 3
Edit|goto|special|visible cells only

What's selected?

The same thing happens in code.

Using .specialcells with a single cell can give you unwanted results.

And the same kind of thing can happen when you do Edit|replace. If only
one
cell is selected, the whole sheet (visible cells only) are affected.

So you'll want to make sure that the number of rows visible after the
filter is
bigger than 0.

One way:

With activesheet.AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible). Count = 1
Then
MsgBox "only the headers are visible"
else
'resize to avoid the header
'and come down one row
Set VisRng = .Resize(.Rows.Count - 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With


Otto Moehrbach wrote:

Excel XP & Win XP
I have headers in row 2.
I have data in row 3 only, therefore, RngToCopy is B3. This is correct.
I invoke an Auto-Filter on the data and, as a result, there are NO
visible
rows (below the header row).
I have the following 2 message boxes:
MsgBox RngToCopy.Address(0, 0)
MsgBox RngToCopy.SpecialCells(xlCellTypeVisible).Count
The first MsgBox gives B3. Correct.
The second MsgBox gives 16776960 which is very close to the number of
cells
in the sheet!!.
Since B3 is the RngToCopy and B3 is hidden (by filter), I expected the
second MsgBox to give a zero.
How can I get the count of visible cells in a range if all the cells in
the
range are hidden?
Or, to put it another way, how can I determine that no rows satisfied the
filter criteria?
Thanks for your time. Otto


--

Dave Peterson



Reply
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
Auto filter hidden cells Chiccada Excel Discussion (Misc queries) 1 February 19th 10 10:58 AM
Do not count hidden cells mac Excel Discussion (Misc queries) 2 August 28th 07 10:20 AM
Is it possible to not count hidden cells? Jimbob Excel Discussion (Misc queries) 5 July 31st 07 01:05 AM
Filling both hidden and visible cells once a filter has been applied Corrie Excel Programming 0 December 28th 06 05:20 PM
Count with Hidden cells Stretch Excel Discussion (Misc queries) 5 July 9th 05 11:55 PM


All times are GMT +1. The time now is 03:28 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"