If you are building a worksheet with some VBA in it and you are willing to have only one sheet visible in a time, then you need a small piece of code, hiding all other sheets.
What we should do? Simply a for-each loop which goes through all the sheets and checks their name. If the name is different from the name of the current active sheet, you simply need to hide it.
There it goes:
1 2 3 4 5 6 7 8 9 10 11 12 |
Sub <span class="hiddenSpellError">HideWorksheets</span>() Dim <span class="hiddenSpellError">ws</span> As Worksheet Dim <span class="hiddenSpellError">sName</span> As String <span class="hiddenSpellError">sName</span> = ThisWorkbook.ActiveSheet.Name For Each <span class="hiddenSpellError">ws</span> In ThisWorkbook.Worksheets If <span class="hiddenSpellError">ws</span>.Name <> <span class="hiddenSpellError">sName</span> Then ws.Visible = xlSheetHidden Next ws End Sub |
🙂