Vba 紧凑式错误检查

Vba 紧凑式错误检查,vba,Vba,有没有一种优雅的方法来编写if A或B或C then X else do nothing语句?例如 If WorksheetFunction.CountA(Range("J:J")) <> SymbolCount Then MsgBox "Check column J in Estate worksheet for fill completion" End If If WorksheetFunction.CountA(Range("K:K")) <> Symbol

有没有一种优雅的方法来编写if A或B或C then X else do nothing语句?例如

If WorksheetFunction.CountA(Range("J:J")) <> SymbolCount Then
    MsgBox "Check column J in Estate worksheet for fill completion"
End If
If WorksheetFunction.CountA(Range("K:K")) <> SymbolCount Then
    MsgBox "Check column K in Estate worksheet for fill completion"
End If
如果工作表function.CountA(范围(“J:J”))SYMBOL然后计数
MsgBox“检查遗产工作表中的J栏是否填写完整”
如果结束
如果工作表function.CountA(范围(“K:K”))SymbolCount,则
MsgBox“检查遗产工作表中的K列是否填写完整”
如果结束
我能想到的最有创意的解决方案是添加CountAs,看看它是否匹配SymbolCount*NumberOfTests,但这意味着给出一个非特定的响应消息

这里是一个尝试(如果我很理解你的问题):

子测试()
Dim SymbolCount为整数,i为整数
作为字符串的Dim aCols(2)
aCols(0)=“J”
aCols(1)=“K”
SymbolCount=0
对于i=0到UBound(aCols)-1
如果工作表function.CountA(范围(aCols(i)&“&aCols(i)))符号计数,则
MsgBox“检查栏”和aCols(i)以及“填写完成的房地产工作表”
如果结束
接下来我
端接头
Sub test()
Dim SymbolCount As Integer, i As Integer
Dim aCols(2) As String
aCols(0) = "J"
aCols(1) = "K"

SymbolCount = 0
For i = 0 To UBound(aCols) - 1
    If WorksheetFunction.CountA(Range(aCols(i) & ":" & aCols(i))) <> SymbolCount Then
        MsgBox "Check column " & aCols(i) & " in Estate worksheet for fill completion"
    End If
Next i
End Sub