我在一个工作簿中有多张工作表。
NotToTouchSheet1,NotToTouch Sheet2,NotToTouch Sheet3,NotToTouchSheet4,HideOrToUnhideSheet1,HideOrtoUnhideSeet2。。。,隐藏或取消隐藏Sheet10
正如你在上面看到的,无论发生什么,我都不想隐藏一些床单,以及在特定情况下需要隐藏或取消隐藏的床单。
条件是,当用户从组合框中选择一个值时,组合框会列出从数组中吐出的图纸名称。
我的问题是,考虑到我拥有的工作表数量,我如何让它隐藏那些不在范围/数组中的工作表,再加上那些我不希望它们隐藏"NotToTouchSheet"的工作表。
例如,用户从组合框列表中选择"a""值由HideOrToUnhideSheet1、HideOrtoUnhideSeet3和HideOrTo UnhideSsheet5组成。因此,我希望显示"NotToTouchSheet"表,包括"HideOrToUnhideSheet1,3和5",并隐藏其余的表。
当用户从组合框列表中选择"B"时B'值由HideOrToUnhideSheet8、HideOrtoUnhideSeet9和HideOrTo UnhideSSheet10组成。由于这些表是隐藏的,我想取消隐藏,并隐藏HideOrToUnhideSheet1,3和5。
我希望上面的例子能帮助你理解和想象我想要实现的目标。
myArray = Split(blah, "|")
inputCell = 4
For Each sht In Worksheets
For myArrayIndex = LBound(myArray) + 1 To UBound(myArray) - 1
commName = Replace(myArray(myArrayIndex), " Consol", "")
If (sht.Tab.Color = 192 Or sht.Tab.Color = 5296274) And (sht.Name Like "* Consol" Or sht.Name Like "* Detail") Then
if the above condition is true, hide those sheets that are not in the array PLUS those 'NotToTouchSheet'
End If
Next myArrayIndex
Next sht
能够通过"隐藏"工作表,然后另一个循环来检查工作表是否是我想要取消隐藏的工作表来解决此问题。
myArray = Split(blah, "|")
inputCell = 4
For Each sht In Worksheets
If (sht.Tab.Color = 192 Or sht.Tab.Color = 5296274) And (sht.Name Like "* Consol" Or sht.Name Like "* Detail") Then
sht.Visible = xlSheetHidden
End If
Next sht
For Each cell In myArray
If cell <> "" Then
dtlCommName = Replace(cell, " Consol", " Detail")
If Sheets(cell).Visible = xlSheetHidden Or Sheets(dtlCommName).Visible = xlSheetHidden Then
Sheets(cell).Visible = xlSheetVisible
Sheets(dtlCommName).Visible = xlSheetVisible
End If
Sheets("Consolidation Summary").Range("AB" & inputCell).Value = cell
inputCell = inputCell + 1
End If
Next cell