I do some filtering on a range and copy that filtered range with
myRange.SpecialCells(xlCellTypeVisible).Copy
As soon as the filter filters
I stored the solution into a function. Here I use an error on mechamism.
Function errorCatchEmptyFilter(ByRef rngstart As Range) As Boolean
errorCatchEmptyFilter = False
'here I get an error if there are no cells
On Error GoTo hell
Set rngFiltered = rngstart.SpecialCells(xlCellTypeVisible)
Exit function
hell:
errorCatchEmptyFilter = True
End Function
Got the same problem, but for filtering named table, solved it this way*:
true
values in that column.SpecialCells(xlCellTypeVisible).Copy
, else skip to next step (i was doing that in a loop)*I know that this question is from 2015, but I've ended here in 2019 googling similar problem so I'm leaving my solution.
What I do is I am counting filtered rows :
Sheets("Sheet1").Range("A2:Z2").AutoFilter
Sheets("Sheet1").Range("A2:Z2").AutoFilter Field:=1, Criteria1:=filter1
If Sheets("Sheet1").AutoFilter.Range.Columns(4).SpecialCells(xlCellTypeVisible).Count > 1 Then
you can change number of column to suits your needs
On Error Resume Next
Set rngFiltered = rngStart.SpecialCells(xlCellTypeVisible)
On Error Goto 0
If not rngFiltered is Nothing then
rngFiltered.Copy
End If