【发布时间】:2020-10-27 22:02:16
【问题描述】:
这是我用来过滤数据和创建多个报告的当前代码。它在 A 列 (FS) 中搜索文本并停止隐藏行,直到到达空白单元格,然后再次隐藏所有内容,直到到达下一个文本 (LR)。
不过,我需要保留该空白行,因为它包含我需要的数据,然后在该行之后开始“隐藏”过程。非常感谢任何帮助,因为我是 VBA 新手。
Sub RunReport()
Set R = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
hiderow = False
For Each c In R.Cells
If Left(c.Value, 2) = "FS" Then
hiderow = False
ElseIf Left(c.Value, 2) = "LR" Then
hiderow = False
ElseIf Left(c.Value, 2) = "SR" Then
hiderow = False
ElseIf Left(c.Value, 3) = "ROG" Then
hiderow = False
ElseIf Left(c.Value, 8) = "ST" Then
hiderow = False
ElseIf Len(c.Value) = 0 Then
hiderow = True
End If
If hiderow Then
c.Select
Selection.EntireRow.Hidden = True
End If
Next c
End Sub
【问题讨论】:
-
将
hiderow = False作为循环内的第一行。 -
好吧,我正在尝试根据这些标题进行专门过滤。您提供的代码仅过滤掉空白单元格,并没有隐藏相应的数据。我真的只需要它是 hiderow + 1,但无法弄清楚如何正确地做到这一点。