What to do when autofilter in VBA returns no data?

后端 未结 5 1745
北恋
北恋 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 08:53

    You can put the code blow into a function.

    Set myRange = Workbooks(KGRReport).Worksheets(spreadSheetName).Range("B2:H" & lastrowinSpreadSheet).SpecialCells(xlVisible)
    

    In the function, use on error goto xxxx. When error return nothing from the function and use "if myRange is not nothing then" to ignore the error cells.

提交回复
热议问题