我想显示列表中的工作表(背景选项卡),然后隐藏其余部分。下面的 VBA 可以工作,但可以缩短。我尝试了 For i=1 等,但无济于事。有人可以缩短这个 VBA 吗?
子表_隐藏()
Dim ws As Worksheet
Dim i As Integer
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> Sheets("Background").Range("AC4").Value Then
If ws.Name <> Sheets("Background").Range("AC5").Value Then
If ws.Name <> Sheets("Background").Range("AC6").Value Then
If ws.Name <> Sheets("Background").Range("AC7").Value Then
If ws.Name <> Sheets("Background").Range("AC8").Value Then
If ws.Name <> Sheets("Background").Range("AC9").Value Then
If ws.Name <> Sheets("Background").Range("AC10").Value Then
If ws.Name <> Sheets("Background").Range("AC11").Value Then
If ws.Name <> Sheets("Background").Range("AC12").Value Then
If ws.Name <> Sheets("Background").Range("AC12").Value Then
If ws.Name <> Sheets("Background").Range("AC12").Value Then
If ws.Name <> Sheets("Background").Range("AC13").Value Then
If ws.Name <> Sheets("Background").Range("AC14").Value Then
If ws.Name <> Sheets("Background").Range("AC15").Value Then
ws.Visible = xlSheetHidden
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
下一个 ws
子目录结束
答案1
Sub Sheets_Hide()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Not Worksheets("Background").Range("AC4:AC15") _
.Find(ws.Name,LookAt:=xlWhole) Is Nothing Then
ws.Visible = xlSheetHidden
End IF
Next ws
End Sub
或者
Sub Sheets_Hide()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If Worksheets("Background").Range("AC4:AC15") _
.Find(ws.Name,LookAt:=xlWhole) Is Nothing Then
ws.Visible = xlSheetVisible
Else
ws.Visible = xlSheetHidden
End IF
Next ws
End Sub
不确定为什么单元格中的 OP 值AC12正在测试三次。可能出现错误:复制粘贴粘贴粘贴...修改修改修改...