我目前正在研究一个宏,该宏查看主工作表中的特定单元格值,并确定是否应隐藏或显示工作簿中的某些工作表。 (例如,如果主工作表的单元格E13为0,则应隐藏工作表“ bank”)。该工作簿有多个单元需要评估,因此我尝试使用For Next循环来实现此目的,但是每次进入该循环时,都会出现错误消息“对象不支持此属性或方法”。我不确定为什么会这样吗?
Sub Calculate_Sheet()
If Not ActiveWorkbook Is ThisWorkbook Then Exit Sub
Dim ws() As String
Dim i As Long
Dim index As Long
Dim FinalRow As Long
FinalRow = Cells(Rows.Count, "D").xlEnd(Up).Row
For i = 13 To FinalRow
index = i - 13
ReDim ws(0 To index)
ws(index) = Cells(i, "A").Value
If Cells(i, "E").Value = 0 And Cells(i, "F").Value = 0 Then
Worksheets(ws(index)).Visible = xlHidden
Else
Worksheets(ws(index)).Visible = xlVisible
End If
Next i
End Sub