【问题标题】:VBA - Hide rows macro limitVBA - 隐藏行宏限制
【发布时间】:2018-07-05 17:04:53
【问题描述】:

我有下面的代码来隐藏工作表上的所有空白单元格。如何将隐藏范围设置为 100,以便在单元格 100 之后,如果其余的为空白,则不会隐藏它们。如果为空白,则只有 1-100 限制内的单元格会被隐藏。

Sub HideRow()

    Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets("Projects Dashboard")
    Dim LRowC, LRowD, LRowF, LRowH, LRow As Long
    LRowC = ws.Range("C" & ws.Rows.Count).End(xlUp).Row
    LRowD = ws.Range("D" & ws.Rows.Count).End(xlUp).Row
    LRowF = ws.Range("F" & ws.Rows.Count).End(xlUp).Row
    LRowH = ws.Range("H" & ws.Rows.Count).End(xlUp).Row
    LRow = Application.WorksheetFunction.Max(LRowC, LRowD, LRowF, LRowH)

    Dim I As Long

    Application.ScreenUpdating = False
    ws.Rows.Hidden = False
    For I = LRow To 7 Step -1
        If ws.Range("C" & I).Text = "" And ws.Range("D" & I).Text = "" And ws.Range("F" & I).Text = "" And ws.Range("I" & I).Text = "" Then
            ws.Rows(I).EntireRow.Hidden = True
        End If
    Next I
    Application.ScreenUpdating = True

End Sub

【问题讨论】:

  • LRowH 基于H 列,但是当您检查内容是否为空时,您会检查I 列中的值。这是想要的吗?
  • @cybernetic.nomad, column I?,请重新检查代码。
  • 来自您的代码:And ws.Range("I" & I).Text,请再次查看代码。
  • 抱歉,错过了最后一个范围。
  • 请澄清您的问题,您是要在前 100 个空单元格还是 100 行之后停止?

标签: vba excel excel-formula excel-2010


【解决方案1】:

如果我理解您的问题和代码,您似乎希望将 LRow 值限制为最大 100。

应该就像添加一行代码一样简单:

...    
LRow = Application.WorksheetFunction.Max(LRowC, LRowD, LRowF, LRowH)

If LRow > 100 Then LRow = 100

Dim I As Long
...

【讨论】:

  • 是的,完美!非常感谢雷伊。
猜你喜欢
  • 2013-09-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-10
  • 1970-01-01
  • 2022-11-30
  • 2019-12-04
  • 1970-01-01
  • 2013-09-25
相关资源
最近更新 更多