We help IT Professionals succeed at work.

filter and if blank continue with next piece of code

Jagwarman asked
could an expert provide me with vba code that will enable my macro to continue onto the next piece of code if there is no data after a filter

The code I have is

ActiveCell.AutoFilter Field:=14
        ActiveCell.AutoFilter Field:=15, Criteria1:="<>"
        rngFilterRangePublic.SpecialCells(12).Offset(0, 12).Copy Destination:=Workbooks(wkbk).Sheets("calc").Range("e3")
        rngFilterRangePublic.SpecialCells(12).Offset(0, 16).Copy Destination:=Workbooks(wkbk).Sheets("calc").Range("f3")

which falls over because in some cases there is no data within the filter

Thank you
Watch Question

Most Valuable Expert 2011
Top Expert 2011
Try this:

    ActiveCell.AutoFilter Field:=14
    ActiveCell.AutoFilter Field:=15, Criteria1:="<>"
    If ActiveSheet.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count > 1 Then
        With rngFilterRangePublic.SpecialCells(12)
            .Offset(0, 12).Copy Destination:=Workbooks(wkbk).Sheets("calc").Range("e3")
            .Offset(0, 16).Copy Destination:=Workbooks(wkbk).Sheets("calc").Range("f3")
        End With
    End If

Open in new window


Rory that's perfect many thanks