简体   繁体   English

自动筛选和停止宏中没有空白字段时的Excel VBA消息框

[英]Excel VBA Message Box when there are no blank fields in an autofilter and stop macro

I have a simple macro to set one AutoFilter column(field 4) to a particular value, and a second AutoFilter column(field 5) to show only blank entries. 我有一个简单的宏,可将一个“自动过滤器”列(字段4)设置为特定值,第二个“自动过滤器”列(字段5)仅显示空白条目。 Sometimes there are no blank entries and in this situation is there a way to stop the filter function and provide a message box to notify no blank entries were found? 有时没有空白条目,在这种情况下,有没有办法停止过滤器功能并提供一个消息框通知没有找到空白条目?

When my code ends currently, the column(field 5) where there are no blanks to filter actually looks like an autofilter has been applied looking at the change of dropdown arrow state. 当我的代码当前结束时,实际上没有空白要过滤的列(字段5)看起来就像应用了自动过滤器来查看下拉箭头状态的变化。 The full non-blank cells are visible still. 完整的非空白单元仍然可见。

Sub PoPODRecvdStatus()
'
' PoPODRecvdStatus Macro
' Filters Courier/Status by POD Received and Consignment to Blank
'
Application.ScreenUpdating = False
'
ActiveSheet.Range("$A$1:$K$12543").AutoFilter Field:=4, Criteria1:= _
    "POD RECEIVED"
ActiveSheet.Range("$A$1:$K$12543").AutoFilter Field:=5, Criteria1:="<>"
Application.ScreenUpdating = True
End Sub

Based on the comment I understand you might want to have something like that. 根据评论,我了解您可能想要类似的内容。 The code will display a message box if there is no blank cell when filtered on POD RECEIVED and display these lines otherwise it will display the "blanks" with POD RECEIVED 如果在POD RECEIVED上进行过滤时,如果没有空白单元格,则代码将显示一个消息框,并显示这些行,否则它将显示POD RECEIVED的“空白”

Sub PoPODRecvdStatus()
'
' PoPODRecvdStatus Macro
' Filters Courier/Status by POD Received and Consignment to Blank
'
    Application.ScreenUpdating = False
    '
    ActiveSheet.Range("$A$1:$K$12543").AutoFilter Field:=4, Criteria1:= _
                                                  "POD RECEIVED"
    ActiveSheet.Range("$A$1:$K$12543").AutoFilter Field:=5, Criteria1:="="

    Dim rng As Range
    Set rng = ActiveSheet.AutoFilter.Range
    If rng.Columns(5).SpecialCells(xlCellTypeVisible).Count - 1 = 0 Then
        MsgBox "No blank cells in column 5 for POD RECEIVED", vbOKOnly, "POD_RECEIVED"
        ActiveSheet.Range("$A$1:$K$12543").AutoFilter Field:=5, Criteria1:="<>"
    End If
    Application.ScreenUpdating = True

End Sub

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

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