简体   繁体   English

当autofilter什么都不返回时,清除过滤器和结束宏

[英]When autofilter returns nothing, clear filter and end macro

I have this macro that runs a filter and delete the results, but today the filter results brought back nothing and i got an error. 我有这个宏运行过滤器并删除结果,但今天过滤结果没有带回任何东西,我得到一个错误。 I want to make it so that when the filter in the AV range results in nothing, just clear the filter and end sub 我想这样做,以便当AV范围内的滤镜没有任何结果时,只需清除滤镜和结束子

this problem occurs after the "Em Aberto- 00" filter. 在“Em Aberto- 00”过滤器之后出现此问题。

I have tried some suggestions, but being a noob that i am, most of them i could'nt understand what was going on 我已经尝试了一些建议,但作为一个菜鸟,我是大多数人,我无法理解发生了什么

Columns("J:J").Select
Selection.TextToColumns Destination:=Range("J1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 4), TrailingMinusNumbers:=True
Columns("K:K").Select
Selection.TextToColumns Destination:=Range("K1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 4), TrailingMinusNumbers:=True

Columns("BD:BF").Select
Selection.Replace What:="", Replacement:="0", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False


Range("A1").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.AutoFilter
ActiveWindow.SmallScroll ToRight:=31
Range("AV3").Select
ActiveSheet.Range("$A$1:$BK$3018").AutoFilter Field:=48, Criteria1:= _
    "Em Aberto- 00"

Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.EntireRow.Delete
ActiveSheet.ShowAllData
End Sub

Do something like this: 做这样的事情:

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
    Exit Sub
Else
'do stuff
End If

You should avoid using SELECT , just Google "how to avoid using SELECT VBA" 你应该避免使用SELECT ,只是谷歌“如何避免使用SELECT VBA”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM