If AutoFilter Hides All, .Count Finds Row 8000 Rather than Row 1
Hello,
I have a macro that performs an autofilter on a table, and then finds the last row using .Count in order to copy the column to another sheet. This has been working fine, but then I came across a problem. If the filter ends up hiding all of the rows, the .rows.count method ends up finding the last row in the worksheet, rather than finding row 1 which is the only row visible.
Does anyone know why this is happening, and how I can fix the problem?
Below is an example of what my code looks like. When the AutoFilter hides all rows except the title bar, it should not copy a range... instead it copies all 8000 files that were visible before the autofilter. After testing, LR is coming up as the last row in the worksheet prior to the autofilter.
Hello,
I have a macro that performs an autofilter on a table, and then finds the last row using .Count in order to copy the column to another sheet. This has been working fine, but then I came across a problem. If the filter ends up hiding all of the rows, the .rows.count method ends up finding the last row in the worksheet, rather than finding row 1 which is the only row visible.
Does anyone know why this is happening, and how I can fix the problem?
Below is an example of what my code looks like. When the AutoFilter hides all rows except the title bar, it should not copy a range... instead it copies all 8000 files that were visible before the autofilter. After testing, LR is coming up as the last row in the worksheet prior to the autofilter.
Code:
Dim rngData As Range, LR As Long, CLIENT as Long
With Worksheets("REPORT")
Set rngData = Range("A1").CurrentRegion
CLIENT = Application.WorksheetFunction.Match("Client_ID", Range("1:1"), 0)
rngData.AutoFilter Field:=Active, Criteria1:="A"
LR = .Cells(.Rows.Count, CLIENT).End(xlUp).Row
If LR > 1 Then
.Range(.Cells(2, CLIENT), .Cells(LR, CLIENT)).Copy _
Sheets("DailyReport").Range("A3")
End If
End With
Last edited: