What to do when autofilter in VBA returns no data?

后端 未结 5 1744
北恋
北恋 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:09

    Try error handling like so:

    Dim myRange As Range
    
    On Error Resume Next
    Set myRange = Range("your range here").SpecialCells(xlVisible)
    On Error GoTo 0
    
    If myRange Is Nothing Then
        MsgBox "no cells"
    Else
        'do stuff
    End If
    

提交回复
热议问题