I do some filtering on a range and copy that filtered range with
myRange.SpecialCells(xlCellTypeVisible).Copy
As soon as the filter filters all cases I get
Error 1004 No cells were found
I am looking for a way to check (without an On Error
) if the filtered range is empty.
I already tried to set a range with lastRow = .Cells(.Rows.Count, ColumnName).End(xlUp).Row
and check if lastRow > 0
but with this way I also count the filtered (or hidden) row contents.
I also tried
Sub test()
Dim rngStart As Range
Dim rngFiltered As Range
Set rngStart = Sheets(1).Range("A1:A6")
Set rngFiltered = rngStart.SpecialCells(xlCellTypeVisible).Select
If rngFiltered.Rows.Count = 0 Then
MsgBox ("No Cases")
Else
MsgBox ("Found Cases")
End If
End Sub
But here I get the error "No cells found" in the Set rngFiltered
line as well.
I have no header row, since the filter is so complex that I programmed it without using the .Sort
function
On Error
? – RoryOn Error Resume Next
, assign the visible cells to aRange
variable, thenOn Error Goto 0
and then test if the range isNothing
. Since you haven't posted the code that hid the rows, it's hard to suggest another way. – Rory