我在下面有两个代码,一个隐藏行,另一个根据其中包含的值的总和为零来取消隐藏行。但是,此代码还隐藏了我不想要的空白行,因为它们是部分之间的间隔。任何建议都会受到赞赏,如果有改进现有代码的建议,我也将不胜感激。
Sub HideRows()
Dim R As Long
Dim Rng As Range
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange
End If
For R = 1 To Rng.Rows.Count
If Application.Sum(Range(Rng(R, 3), Rng(R, Rng.Columns.Count))) = 0# Then
Rng.Rows(R).Hidden = True
End If
Next R
End Sub
Sub UnHideRows()
Dim R As Long
Dim Rng As Range
If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange
End If
For R = 1 To Rng.Rows.Count
If Application.Sum(Range(Rng(R, 3), Rng(R, Rng.Columns.Count))) = 0# Then
Rng.Rows(R).Hidden = False
End If
Next R
End Sub