当单元格区域为空时,隐藏整行

我有一系列的单元格B2:AB40。

如果范围内每行的每个单元格都是空白的(我的意思是没有文本或数字,只是颜色填充和边框格式),我想用macros来隐藏整行。

例如

If every cell in the range B2:AB2 is blank then hide all of row 2. If every cell in the range B3:AB3 is blank then hide all of row 3 If every cell in the range B4:AB4 is blank then hide all of row 4..etc etc etc 

直到并包括第40行。

注意:A列中的每个单元格与指定范围内每一行中的AC都将始终有文本(分别是某人的姓名和公式结果),并且不能更改。

我已经看到了基于单个单元格的多种方法,但似乎无法使其适用于我的目的。

任何帮助表示赞赏。

考虑:

 Sub RowHider() Dim I As Long, wf As WorksheetFunction Set wf = Application.WorksheetFunction For I = 2 To 40 If wf.CountA(Range("B" & I & ":AB" & I)) = 0 Then Rows(I).Hidden = True Else Rows(I).Hidden = False End If Next I End Sub 

请注意在VBA中使用工作表函数

尝试这个

 Sub HideRangeIfEmpty() If Application.WorksheetFunction.CountA(Range("b2:AB2")) = 0 Then Range("b2:AB2").EntireRow.Hidden = True End If End Sub