[英]Excel VBA + Hide and/or Unhide Sheets via Array range
我的工作簿中有多个工作表。
NotToTouchSheet1,NotToTouchSheet2,NotToTouchSheet3,NotToTouchSheet4,HideOrToUnhideSheet1,HideOrToUnhideSheet2,... ...,HideOrToUnhideSheet10
正如您在上面看到的,无论发生什么情况,都有我不想隐藏的工作表,并且根据条件可以隐藏或取消隐藏工作表。
条件是,当用户从组合框选择一个值时,组合框列出了从数组中吐出的工作表名称。
我的问题是,考虑到我所拥有的工作表数量,我如何使其隐藏那些不在范围/数组中的工作表以及我不希望它们隐藏“ NotToTouchSheet”的工作表。
例如,用户从组合框列表中选择“ A”。 “ A”值包括HideOrToUnhideSheet1,HideOrToUnhideSheet3,HideOrToUnhideSheet5。 因此,我希望显示“ NotToTouchSheet”表,其中包括“ HideOrToUnhideSheet1,3和5”,其余的隐藏。
当用户从组合框列表中选择“ B”时。 “ B”值包括HideOrToUnhideSheet8,HideOrToUnhideSheet9,HideOrToUnhideSheet10。 由于这些工作表是隐藏的,因此我想取消隐藏它,并隐藏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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.