Macro to hide sheets based upon cell value

J

Joe M.

I need help with 3 macros for hiding sheets:

1) I would like to hide several sheets based upon the value of a cell i.e.
A1 within the sheet to possibly be hidden.

2) I need a macro to unhide all hidden sheets. Some sheets are not hidden.

3) I need to hide certain sheets using the name of the sheet.

Thanks in advance for your help!
Joe M.
 
D

Dave Peterson

#1.

Dim wks as worksheet
for each wks in activesheet.worksheets
if lcase(wks.range("a1").value) = lcase("hideme") then
wks.visible = xlsheethidden
end if
next wks

#2

Dim wks as worksheet
for each wks in activesheet.worksheets
'don't bother to see if it's visible or not
wks.visible = xlsheetvisible
next wks

#3.

Dim wks as worksheet
for each wks in activesheet.worksheets
if lcase(wks.name) like lcase("*somecommonstring*") then
wks.visible = xlsheethidden
end if
next wks

Remember that with #1 and #3, at least one sheet has to be visible.
 
J

Joe M.

Dave,

I created a macro with only the code you showed for #1. I got this error:
Object doesn't support this property or method (Error 438)
What did I do wrong?

Thanks,
Joe M.
 
D

Dave Peterson

It was a typo (times 3).

Use:
For Each wks In ActiveWorkbook.Worksheets
not
For Each wks In ActiveSheet.Worksheets
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top