Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

vba - 根据单元格值隐藏/显示工作表(Hide/Show worksheet based on cell value)

I'm currently working on a Macro that looks at specific cell values in a master worksheet and determines whether certain worksheets within the workbook should be hidden or shown.

(我目前正在研究一个宏,该宏将查看主工作表中的特定单元格值,并确定是否应隐藏或显示工作簿中的某些工作表。)

(for example, if cell E13 of master worksheet is 0 then worksheet "bank" should be hidden).

((例如,如果主工作表的单元格E13为0,则应隐藏工作表“ bank”)。)

The workbook has multiple cells it needs to evaluate, so I tried to use a For Next loop to achieve this but every time I get to the loop the error message Object doesn't suppose this property or method comes up.

(该工作簿需要评估多个单元格,因此我尝试使用For Next循环来实现此目的,但是每次进入该循环时,错误消息Object都不认为此属性或方法会出现。)

I am unsure as to why this is happening?

(我不确定为什么会这样?)

  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 = 1 - 13
ReDim ws(1 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
  ask by Emibigpacem translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...