Quote:
Originally Posted by cosmicyes
FirstVisibleRow is 1, not 16.
What is my mistake?
|
You're probably seeing the Autofilter header row which is never filtered out by the autofilter. The header row is included in the Autofilter.range.
Try:
Code:
Dim VisibleRange As Range, FirstVisibleRow As Long ', LastVisibleRow As Long
With Worksheets("Daten")
Set DataBodyRange = Intersect(.AutoFilter.Range, .AutoFilter.Range.Offset(1)) 'presumes there is an autofilter in place.
On Error Resume Next 'in case all rows are hidden
Set VisibleRange = DataBodyRange.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not VisibleRange Is Nothing Then
FirstVisibleRow = VisibleRange.Row
' Set lastArea = VisibleRange.Areas(VisibleRange.Areas.Count)
' LastVisibleRow = lastArea.Cells(lastArea.Cells.Count).Row
End If
End With
If all rows are filtered out the result for first and last visible rows is the impossible row number zero.