简化OR和和VBA

如何简化这个功能,不重复:简化OR和和VBA

If [F11] = "" Or [F12] = "" Or [F13] = "" Or [F14] = "" Or [F15] = "" Or [F16] = "" Or [F17] = "" Or [F18] = "" Or [F19] = "" Or [F20] = "" Or [F21] = "" Then [...] 

回答:

您可以循环的范围内,并打破如有细胞是""

Option Explicit 

Sub TestBlanks

Dim rngData As Range, rngCell As Range, blnRangeHasBlanks As Boolean

' assume no blanks

blnRangeHasBlanks = False

' iterate range and break on any blank

Set rngData = ThisWorkbook.Worksheets("Sheet1").Range("F11:F21")

For Each rngCell In rngData

If rngCell.Value = "" Then

blnRangeHasBlanks = True

Exit For

End If

Next For

If blnRangeHasBlanks Then

' ... do what you need

End If

End Sub

回答:

您可以检查如果您的范围内存在空白单元格。

Option Explicit 

Sub MyAnswer()

Dim rng As Range

Set rng = ActiveSheet.Range("F10:F100")

If rng.SpecialCells(xlCellTypeBlanks).Cells.Count = 0 Then

' Stuff you need

EndIf

End Sub

以上是 简化OR和和VBA 的全部内容, 来源链接: utcz.com/qa/261022.html

回到顶部