svokke
12-02-2013, 01:31 PM
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:
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
This code works most of the time.
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. :banghead:
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?
I have written following code:
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
This code works most of the time.
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. :banghead:
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?