![](/img/trans.png)
[英]Check a range of cells and if criteria is met message box appears and undos action
[英]Check multiple cells and message box if data missing
有沒有一種方法可以檢查多個范圍,如果它們為空,然后顯示一個消息框並告訴我哪些區域缺少數據? 此刻,我正在輸入內容並進行不同的加載。 想知道是否有更簡單的方法?
我的范圍是:Range(“ C11:D11,F11:G11,I11:J11,C14:F14,I14:J14,C15:F15,I15:J15,B18:J18,B42:J42”))
If WorksheetFunction.CountA(Range("C9:E9")) = 0 Then
Worksheets("Create Form").Range("C9:E9").Select
MsgBox "Please enter information in the required fields."
Exit Sub
End If
If WorksheetFunction.CountA(Range("H9:J9")) = 0 Then
Worksheets("Create Form").Range("H9:J9").Select
MsgBox "Please enter information in the required fields."
Exit Sub
End If
謝謝
有一種檢查多個范圍的方法,在下面的代碼中,它是通過使用For
循環遍歷該范圍的所有Areas
來實現的。
然后,對於每個CurRng
(代表一個區域),檢查WorksheetFunction.CountA(CurRng) = 0
。
碼
Option Explicit
Sub CheckMultipleRanges()
Dim MyMultiRng As Range
Dim CurRng As Range
With Worksheets("Create Form")
' use a variable to set the multiple ranges in it
Set MyMultiRng = .Range("C11:D11,F11:G11,I11:J11,C14:F14,I14:J14,C15:F15,I15:J15,B18:J18,B42:J42")
' loop through all areas in the multi-range
For Each CurRng In MyMultiRng.Areas
If WorksheetFunction.CountA(CurRng) = 0 Then
CurRng.Select
MsgBox "Please enter information in the required fields."
Exit Sub
End If
Next CurRng
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.