帮忙在excel中写一段宏代码,使得A列中有某一个单元格内容为空时,隐藏这个单元格所在的行,,,谢啦

2024-11-23 00:06:33
推荐回答(2个)
回答1:

这代码执行全部的行,65536,会很久哦
For Each rw In ActiveSheet.Rows
If Cells(rw.Row, 1) = "" Then
Rows(rw.Row).Select
Selection.EntireRow.Hidden = True
End If
Next rw
如果指定行数,比如1-20行:
For R=1 to 20
If Cells(R, 1) = "" Then
Rows(R).Select
Selection.EntireRow.Hidden = True
End If
Next R

回答2:

Sub 隐藏()
Dim rng As Range, n As Integer
Application.ScreenUpdating = False
n = Range("A65536").End(xlUp).Row
For Each cell In Range("A1:A" & n)
If cell = 0 Then
If rng Is Nothing Then
Set rng = cell
Else: Set rng = Application.Union(rng, cell)
End If
End If
Next
rng.EntireRow.Hidden = True
Application.ScreenUpdating = True
End Sub