大家好,这里是VBA的新手,我正在努力使我的宏可以在多张纸上工作。我基本上想隐藏和取消隐藏“ B-AB”列(如果它们在第8行中有“ X”)。当前,该宏仅在活动工作表上起作用,而不在活动工作簿上起作用。谢谢!
{{1}}
答案 0 :(得分:2)
您需要在范围对象之前添加.
,该对象已分配给with中指出的图纸:
Sub roll()
Dim sh As Worksheet
Dim c As Range
For Each sh In ActiveWorkbook.Sheets
With sh
Application.ScreenUpdating = False
.Columns("B:AB").Hidden = False
For Each c In .Range("b8:ab8").Cells
If c.Value = "X" Then
c.EntireColumn.Hidden = True
End If
Next c
End With
Next sh
Application.ScreenUpdating = True
End Sub