Thread: Printing
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Printing

Hi Steve,

Am I correct in assuming that by Filtering you mean AutoFilter. If so, the
following code example loops through the worksheets and counts the visible
cells in column 1 of the AutoFiltered range. If greater than 1 then data is
visible. If only 1 then only the column headers are visible.

Note that Rows cannot be counted in non contiguous visible rows. However,
Cells can be counted and hense to resize the filtered range to only one
column and count the cells instead of counting the rows.

Private Sub Test()

Dim ws As Worksheet
Dim rngFilter As Range

For Each ws In Worksheets
With ws
If .AutoFilterMode Then
With .AutoFilter.Range
'Assign first column only to rngFilter
Set rngFilter = _
.Resize(.Rows.Count, 1) _
.SpecialCells(xlCellTypeVisible)
End With

If rngFilter.Cells.Count 1 Then
MsgBox rngFilter.Cells.Count - 1 _
& "rows of data on sht " & ws.Name
Else
MsgBox "Column headers only visible on " & _
ws.Name
End If
Else
MsgBox "No filters set on worksheet " _
& ws.Name
End If
End With
Next ws
End Sub


--
Regards,

OssieMac