Sunday, February 5, 2012

Hide Worksheets automatically on open

I was playing on MrExcel.com a while ago and someone wanted to know how they could keep links active on their new year's sheet but not have all the old years hanging around for people to click on. Someone else suggested he just hide the old year's sheets and he wanted to know if he could do that automatically which led me to write this code that might be helpful for many times you want to hide sheets for one reason or another. This code hides any sheet that is named for a year that has already passed. It runs when the workbook opens and has an error check to make sure that it doesn't try to hide every sheet in the workbook (can't have that!!!).
I can think of many uses for this and it wouldn't just have to be sheet names. You could have it check cell A1 on every sheet and hide the sheets that have a specific entry, or you could put dates in cell A1 and then as the workbook opens, the code would compare the dates in cell A1with today and only unhide those sheets that are for that day. You could have a workbook that many people use and have them enter their name into an input box and then have it hide every worksheets except that user's. I could go on and on ;) Anyway here is that code (you would put this in the Workbook module):

1 comment:

  1. By the way, your sheets have to be named with year names - ie 2011 and 2012 etc

    ReplyDelete