How can I Hide Excel rows if SUM of contents = zero and skip blanks?

I have two codes, below, one that hides and the other that unhides rows based on the sum of values contained therein equaling zero. However, this code also hides blank rows which I do not want since they are spacers between sections. Any advice would be apprecated, and if there are recommendations to improve the existing code I would appreciate that as well. 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
If your code speed is an issue it would be quicker to use a "working column" that returns True or False, than an autofilter (manually or with VBA) to hide the rows.

以上就是How can I Hide Excel rows if SUM of contents = zero and skip blanks?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » excel

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏