Excel VBA,更新特定工作表而不仅仅是活动工作表

时间:2017-09-07 03:10:49

标签: excel vba excel-vba

如果行有" - "我创建了一个隐藏活动工作表中行的脚本。我想将其应用于其他纸张(即Sheet-ABC,Sheet-DEF)。我尝试使用数组,但没有成功。

感谢任何帮助。

Sub hideRows()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False


Dim cell, cell2 As Range, hRws As Range
Set Rng = Sheet15.Range("A52:L359")

Rng.EntireRow.Hidden = False

For Each cell In Range("A52:L359").SpecialCells(xlBlanks)
If cell = "-" And cell.Offset(-1, 0) = "-" Then
If hRws Is Nothing Then
Set hRws = Range(cell, cell.Offset(1, 0))

Else
Set hRws = Union(hRws, Range(cell, cell.Offset(1, 0)))
End If
End If
Next

If Not hRws Is Nothing Then hRws.EntireRow.Hidden = True

Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub

1 个答案:

答案 0 :(得分:0)

您可以在for循环中调用hideRows()方法。像这样:

Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets hideRows() Next