View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default How to check row is hidden when apply filter

You could check the .hidden property of the cell or you could just loop through
the visible cells.

Here's a sample of the second:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim VisRng As Range
Dim myRng As Range
Dim myCell As Range

Set wks = ActiveSheet

With wks
'just a single column
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))

'remove any existing filter
.AutoFilterMode = False
myRng.AutoFilter Field:=1, Criteria1:="somevalue"

With .AutoFilter.Range.Columns(1)
If .Cells.SpecialCells(xlCellTypeVisible) = 1 Then
MsgBox "only header visible"
Else
'avoid the header
Set VisRng = .Resize(.Cells.Count - 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
For Each myCell In VisRng.Cells
MsgBox myCell.Address 'or whatever you need to do
Next myCell
End If
End With
.AutoFilterMode = False 'remove the filter
End With
End Sub

moonhk wrote:

On 2月11日, 上午9時17分, Dave Peterson wrote:
You can count the visible cells in a column in the autofilter range:

With activesheet.autofilter.range.columns(1)
if .cells.count = .cells.specialcells(xlcelltypevisible).cells.count then
'all visible
else
'not all visible
end if
end with

But that doesn't tell you if the data has been filtered--it could be that all
the cells in the filter meet the criteria, so that all rows are visible.

If that is important, you may want to check something like:

With activesheet
if .autofiltermode = true then
'there are autofilter arrows on the worksheet
if .filtermode then
'some filter is applied
'maybe show all the data
.showalldata '????
end if
end if
end with

moonhk wrote:

Hi All


For Excel 2003
When Apply Filter , How to check the row have been filtered out ?


Below coding include filtered out row.


iRows = Application.Selection.Rows.Count
iCols = Application.Selection.Columns.Count


For ir = 1 To iRows
....
Next


--

Dave Peterson


Hi All

When Apply filter , some row have been hidden, When I select some row
to process. the hidden also selected. How to check the row is filter
out by filters ?

e.g.
line 1
line 2 <- Filter out
line 3

When select line1 to line3 , the filter out still selected within
blelow for loop

For ir = 1 To iRows
....
Next

moonhkt


--

Dave Peterson