![如果行的所有单元格中都有数据,则隐藏行](https://linux22.com/image/1579698/%E5%A6%82%E6%9E%9C%E8%A1%8C%E7%9A%84%E6%89%80%E6%9C%89%E5%8D%95%E5%85%83%E6%A0%BC%E4%B8%AD%E9%83%BD%E6%9C%89%E6%95%B0%E6%8D%AE%EF%BC%8C%E5%88%99%E9%9A%90%E8%97%8F%E8%A1%8C.png)
我找遍了所有地方,但还是找不到适合我问题的答案。我想知道是否有人可以帮我找出代码。
如果某一行中的所有单元格都包含数据,则隐藏该行;如果该行中有空白单元格,则不要隐藏它。对整个命名范围重复此操作。
我希望这是有道理的!
谢谢!
答案1
像这样:
Sub hideFullRow()
Dim rng As Range
Dim rw As Range
Dim c As Range
Dim hide As Boolean
hide = True
Set rng = Range("Name")
For Each rw In rng.Rows
For Each c In rw.Cells
If IsEmpty(c) Then
hide = False
exit For
End If
Next
rw.EntireRow.Hidden = hide
Next
End Sub