Hi all
I need to program a macro that will hide certain sheets on workbook startup depending on a certain cell and if that certain cell is changed while the workbook is open. To accomplish this I have written the following macro.
Private Sub Workbook_Open()
'Macro to hide either Clarity or CTR related sheets'
If Sheets("Sheet2").Range("BD2") = "CTR" Then
Sheets("Sheet7").Visible = xlVeryHidden
Sheets("Sheet17").Visible = xlVeryHidden
Sheets("Sheet16").Visible = xlVeryHidden
Sheets("Sheet26").Visible = xlVeryHidden
Sheets("Sheet27").Visible = xlVeryHidden
ElseIf Sheets("Sheet2").Range("BD2") = "Clarity" Then
Sheets("sheet8").Visible = xlVeryHidden
Sheets("sheet19").Visible = xlVeryHidden
Sheets("sheet18").Visible = xlVeryHidden
Sheets("sheet23").Visible = xlVeryHidden
Sheets("sheet22").Visible = xlVeryHidden
Else
Exit Sub
End If
End Sub
However, when I run the macro I get the following error "Run-time error '9': Subscript out of range". I can't figure out why - hope someone can help me out?
I have tried using the "Auto_open" instead but gets the same problem. Can it be because I just use the generic sheet names or the total (real) sheet names?
Br, CFL
I need to program a macro that will hide certain sheets on workbook startup depending on a certain cell and if that certain cell is changed while the workbook is open. To accomplish this I have written the following macro.
Private Sub Workbook_Open()
'Macro to hide either Clarity or CTR related sheets'
If Sheets("Sheet2").Range("BD2") = "CTR" Then
Sheets("Sheet7").Visible = xlVeryHidden
Sheets("Sheet17").Visible = xlVeryHidden
Sheets("Sheet16").Visible = xlVeryHidden
Sheets("Sheet26").Visible = xlVeryHidden
Sheets("Sheet27").Visible = xlVeryHidden
ElseIf Sheets("Sheet2").Range("BD2") = "Clarity" Then
Sheets("sheet8").Visible = xlVeryHidden
Sheets("sheet19").Visible = xlVeryHidden
Sheets("sheet18").Visible = xlVeryHidden
Sheets("sheet23").Visible = xlVeryHidden
Sheets("sheet22").Visible = xlVeryHidden
Else
Exit Sub
End If
End Sub
However, when I run the macro I get the following error "Run-time error '9': Subscript out of range". I can't figure out why - hope someone can help me out?
I have tried using the "Auto_open" instead but gets the same problem. Can it be because I just use the generic sheet names or the total (real) sheet names?
Br, CFL