簡體   English   中英

vba 代碼:如果行數 =1,則顯示消息框並停止宏,否則繼續宏

[英]vba code : if the number of rows are =1 then display a message box and stop the macro else continue the macro

我需要以下的 vba 代碼。 如果您可以幫助.vba 代碼,我會很高興:如果行數為 =1(僅適用於可見單元格),則顯示一個消息框並停止宏,否則繼續宏。

If Sheets(1).AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Count = 1 Then
  MsgBox "number of rows = 1"
  End sub
End If

編輯此代碼以滿足您的需求

我使用 xlCellTypeVisible 來計算行數。

子測試1()

Dim Lastrow As Long

Dim ws As Worksheet


Set ws = ThisWorkbook.ActiveSheet

Lastrow = ws.Columns(1).SpecialCells(xlCellTypeVisible).Rows.Count


If Lastrow = 1 Then

     MsgBox " Rows les than 1"
    Exit Sub
Else

End If




End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM