[英]When autofilter returns nothing, clear filter and end macro
我有這個宏運行過濾器並刪除結果,但今天過濾結果沒有帶回任何東西,我得到一個錯誤。 我想這樣做,以便當AV范圍內的濾鏡沒有任何結果時,只需清除濾鏡和結束子
在“Em Aberto- 00”過濾器之后出現此問題。
我已經嘗試了一些建議,但作為一個菜鳥,我是大多數人,我無法理解發生了什么
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
做這樣的事情:
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
你應該避免使用SELECT
,只是谷歌“如何避免使用SELECT VBA”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.