I have the following code to get the first and last rows of a filtered range.
The code works fine when there are 2 or more filtered rows showing, but if only one row is showing, LastInvRow is returned as 1048576.
How can I code for this contingency? I thought of simply checking IF LastInvRow=104576 then LastInvRow = FirstInvRow, but would there be occasions in the future when just one filtered row showing would return a different result than 104576? What is my best way of avoiding this problem?
VBA Code:
With ActiveSheet.AutoFilter.Range
Set rFiltered = .Resize(.Rows.Count - 1).Offset(1).Columns(2).SpecialCells(xlCellTypeVisible)
End With
FirstInvRow = rFiltered.Cells(1, 1).Row
LastInvRow = rFiltered.Cells(1, 1).End(xlDown).Row
The code works fine when there are 2 or more filtered rows showing, but if only one row is showing, LastInvRow is returned as 1048576.
How can I code for this contingency? I thought of simply checking IF LastInvRow=104576 then LastInvRow = FirstInvRow, but would there be occasions in the future when just one filtered row showing would return a different result than 104576? What is my best way of avoiding this problem?