I have an excel 2010 workbook with 50+ worksheets. For the users of this worksheet it is easier if most sheets are hidden. Therefore I would like to hide all sheets, except the worksheets which have "Macropage" as content in cell A1.
I have written following code:
This code works most of the time.Sub HidePart() Dim ws As Worksheet For Each ws In ActiveWorkbook.Worksheets If Range("A1").Value <> "Macropage" Then ActiveWindow.SelectedSheets.Visible = False End If Next ws End Sub
It doesn't work if the Macro is started from a worksheet which has "Macropage" as content in cell A1. In that case not a singe worksheet is hidden and the macro exits without error message.
If it is started from a worksheet with an emty cell A1, it works flawlessly.
Can anyone explain why this macro won't work when it is started from a worksheet with "Macropage" in cell A1?