What to do when autofilter in VBA returns no data?

后端 未结 5 1762
北恋
北恋 2020-12-19 08:51

I am trying to filter a range of values and based on my criteria, at times I might have no data that fits my criteria. In that case, I do not want to copy any data from the

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-19 09:00

    Neither of the responses below worked for me. Here is what I finally found that worked:

    Sub fileterissues()
    
    Dim VisibleRows as Long
    
    ‘Some code here
    
    With Sheets(ws1).Range(“myrange”)
    .Autofilter Field:=myfieldcolumn, criteria:=myfiltercriteria
    VisibleRows = Application.Worksheetfunction.Subtotal(103, sheets(1).mycolumnfieldrange)
    If VisibleRows = 0 then Resume Next
    End with
    
    ‘More code
    
    End sub
    

提交回复
热议问题