• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Stop copy paste if the filtered range has no data

Hi,

I am working Excel 2013,

I need the Autofilter "#N/A" in the "F" column, if filter the "#N/A" no data with the heading, "Goto 0:" code does...

but, my code not working, goto 0:

>>> use code - tags <<<
Code:
Sub testsss()
    'Filter Insert and #N/A Copy and Paste
    'VBA – Turn Off Autofilter From Code
    If ActiveSheet.AutoFilterMode Then
        ActiveSheet.AutoFilterMode = False        'ActiveSheet.Range("A1").AutoFilter ---> Turn On Autofilter
    End If
   
    'Auto Filter 2nd Column Blank Cells filter
    Dim LastRow As Long
    LastRow = Range("B" & Rows.Count).End(xlUp).Row
   
    On Error Resume Next                          'if filter then no data go next
    ActiveSheet.Range("$A$1:$F" & LastRow).AutoFilter Field:=6, Criteria1:="#N/A" 'Not Applicable Cells filter then select visible cells
    Range("$A$2:$F" & LastRow).SpecialCells(xlCellTypeVisible).Select
   
        'Stop copy paste if the filtered range has no data
        If Range("A1:F" & LastRow).SpecialCells(xlCellTypeVisible).Count > 1 Then
            Range("$B$2:$D" & LastRow).SpecialCells(xlCellTypeVisible).Select
            Selection.Copy
            'Do Something Code.........
            Application.CutCopyMode = False
        Else
            ActiveSheet.AutoFilterMode = False
            GoTo 0:
        End If
               
        'Do Something Code.........
       
0:
End Sub


Kindly help me, thanks for advance
 

Attachments

  • Stop copy paste if the filtered range has no data.xlsm
    25.8 KB · Views: 1
Last edited by a moderator:
sivaprakasam
Have You checked - what value do You get then there is none filtered rows ( = all rows could be visible too ) ?
I've use next to solve Your challenge
FilteredRows = .AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1
 
Back
Top