Macro to hide worksheet based upon text in the name

Is it possible to have a macro that hides worksheets based upon text 
contained or not contained in the worksheet name? Suppose i have several 
worksheets but want to hide ony the ones that don't have the text "HOLD" in 
the name;

worksheet names:
Data_HOLD
Data Selection_HOLD
etc....
or maybe base it upon the WS tab color....

Thanks,
Joe M.

0
Utf
4/8/2010 3:38:01 PM
excel.misc 78881 articles. 5 followers. Follow

5 Replies
781 Views

Similar Articles

[PageSpeed] 15

Hi,

This will hide all worksheets with Hold anywhere in the name

Sub Hide_shts()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    If InStr(1, ws.Name, "Hold", vbTextCompare) Then
        ws.Visible = False
    End If
Next
End Sub

-- 
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that 
introduces the fewest assumptions while still sufficiently answering the 
question.


"Joe M." wrote:

> Is it possible to have a macro that hides worksheets based upon text 
> contained or not contained in the worksheet name? Suppose i have several 
> worksheets but want to hide ony the ones that don't have the text "HOLD" in 
> the name;
> 
> worksheet names:
> Data_HOLD
> Data Selection_HOLD
> etc....
> or maybe base it upon the WS tab color....
> 
> Thanks,
> Joe M.
> 
0
Utf
4/8/2010 3:43:01 PM
Thanks. But I have discovered that I will have to rename some other sheets 
for this to work and it will affect some macros. What about by the WS tab 
color? Tis will be easier for me. Sorry for not being sure earlier.

Thx,
Joe M.

"Mike H" wrote:

> Hi,
> 
> This will hide all worksheets with Hold anywhere in the name
> 
> Sub Hide_shts()
> Dim ws As Worksheet
> For Each ws In ThisWorkbook.Worksheets
>     If InStr(1, ws.Name, "Hold", vbTextCompare) Then
>         ws.Visible = False
>     End If
> Next
> End Sub
> 
> -- 
> Mike
> 
> When competing hypotheses are otherwise equal, adopt the hypothesis that 
> introduces the fewest assumptions while still sufficiently answering the 
> question.
> 
> 
> "Joe M." wrote:
> 
> > Is it possible to have a macro that hides worksheets based upon text 
> > contained or not contained in the worksheet name? Suppose i have several 
> > worksheets but want to hide ony the ones that don't have the text "HOLD" in 
> > the name;
> > 
> > worksheet names:
> > Data_HOLD
> > Data Selection_HOLD
> > etc....
> > or maybe base it upon the WS tab color....
> > 
> > Thanks,
> > Joe M.
> > 
0
Utf
4/8/2010 3:55:01 PM
Hi,

This will hide sheets with red tabs

Sub Hide_shts()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
    If ws.Tab.Color = 255 Then
        ws.Visible = False
    End If
Next
End Sub
-- 
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that 
introduces the fewest assumptions while still sufficiently answering the 
question.


"Joe M." wrote:

> Thanks. But I have discovered that I will have to rename some other sheets 
> for this to work and it will affect some macros. What about by the WS tab 
> color? Tis will be easier for me. Sorry for not being sure earlier.
> 
> Thx,
> Joe M.
> 
> "Mike H" wrote:
> 
> > Hi,
> > 
> > This will hide all worksheets with Hold anywhere in the name
> > 
> > Sub Hide_shts()
> > Dim ws As Worksheet
> > For Each ws In ThisWorkbook.Worksheets
> >     If InStr(1, ws.Name, "Hold", vbTextCompare) Then
> >         ws.Visible = False
> >     End If
> > Next
> > End Sub
> > 
> > -- 
> > Mike
> > 
> > When competing hypotheses are otherwise equal, adopt the hypothesis that 
> > introduces the fewest assumptions while still sufficiently answering the 
> > question.
> > 
> > 
> > "Joe M." wrote:
> > 
> > > Is it possible to have a macro that hides worksheets based upon text 
> > > contained or not contained in the worksheet name? Suppose i have several 
> > > worksheets but want to hide ony the ones that don't have the text "HOLD" in 
> > > the name;
> > > 
> > > worksheet names:
> > > Data_HOLD
> > > Data Selection_HOLD
> > > etc....
> > > or maybe base it upon the WS tab color....
> > > 
> > > Thanks,
> > > Joe M.
> > > 
0
Utf
4/8/2010 4:01:02 PM
I tried with several WS with red tabs but it only hides one. I double checked 
to make sure red was selected. What is wrong?

Thanks,

Joe M.




"Mike H" wrote:

> Hi,
> 
> This will hide sheets with red tabs
> 
> Sub Hide_shts()
> Dim ws As Worksheet
> For Each ws In ThisWorkbook.Worksheets
>     If ws.Tab.Color = 255 Then
>         ws.Visible = False
>     End If
> Next
> End Sub
> -- 
> Mike
> 
> When competing hypotheses are otherwise equal, adopt the hypothesis that 
> introduces the fewest assumptions while still sufficiently answering the 
> question.
> 
> 
> "Joe M." wrote:
> 
> > Thanks. But I have discovered that I will have to rename some other sheets 
> > for this to work and it will affect some macros. What about by the WS tab 
> > color? Tis will be easier for me. Sorry for not being sure earlier.
> > 
> > Thx,
> > Joe M.
> > 
> > "Mike H" wrote:
> > 
> > > Hi,
> > > 
> > > This will hide all worksheets with Hold anywhere in the name
> > > 
> > > Sub Hide_shts()
> > > Dim ws As Worksheet
> > > For Each ws In ThisWorkbook.Worksheets
> > >     If InStr(1, ws.Name, "Hold", vbTextCompare) Then
> > >         ws.Visible = False
> > >     End If
> > > Next
> > > End Sub
> > > 
> > > -- 
> > > Mike
> > > 
> > > When competing hypotheses are otherwise equal, adopt the hypothesis that 
> > > introduces the fewest assumptions while still sufficiently answering the 
> > > question.
> > > 
> > > 
> > > "Joe M." wrote:
> > > 
> > > > Is it possible to have a macro that hides worksheets based upon text 
> > > > contained or not contained in the worksheet name? Suppose i have several 
> > > > worksheets but want to hide ony the ones that don't have the text "HOLD" in 
> > > > the name;
> > > > 
> > > > worksheet names:
> > > > Data_HOLD
> > > > Data Selection_HOLD
> > > > etc....
> > > > or maybe base it upon the WS tab color....
> > > > 
> > > > Thanks,
> > > > Joe M.
> > > > 
0
Utf
4/8/2010 4:16:05 PM
I just tested Mikes code successfully. Are they the same color and in the 
same workbook?

-- 
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett@gmail.com
"Joe M." <JoeM@discussions.microsoft.com> wrote in message 
news:D612BB02-6E04-4ED7-9479-B093EE17FC81@microsoft.com...
>I tried with several WS with red tabs but it only hides one. I double 
>checked
> to make sure red was selected. What is wrong?
>
> Thanks,
>
> Joe M.
>
>
>
>
> "Mike H" wrote:
>
>> Hi,
>>
>> This will hide sheets with red tabs
>>
>> Sub Hide_shts()
>> Dim ws As Worksheet
>> For Each ws In ThisWorkbook.Worksheets
>>     If ws.Tab.Color = 255 Then
>>         ws.Visible = False
>>     End If
>> Next
>> End Sub
>> -- 
>> Mike
>>
>> When competing hypotheses are otherwise equal, adopt the hypothesis that
>> introduces the fewest assumptions while still sufficiently answering the
>> question.
>>
>>
>> "Joe M." wrote:
>>
>> > Thanks. But I have discovered that I will have to rename some other 
>> > sheets
>> > for this to work and it will affect some macros. What about by the WS 
>> > tab
>> > color? Tis will be easier for me. Sorry for not being sure earlier.
>> >
>> > Thx,
>> > Joe M.
>> >
>> > "Mike H" wrote:
>> >
>> > > Hi,
>> > >
>> > > This will hide all worksheets with Hold anywhere in the name
>> > >
>> > > Sub Hide_shts()
>> > > Dim ws As Worksheet
>> > > For Each ws In ThisWorkbook.Worksheets
>> > >     If InStr(1, ws.Name, "Hold", vbTextCompare) Then
>> > >         ws.Visible = False
>> > >     End If
>> > > Next
>> > > End Sub
>> > >
>> > > -- 
>> > > Mike
>> > >
>> > > When competing hypotheses are otherwise equal, adopt the hypothesis 
>> > > that
>> > > introduces the fewest assumptions while still sufficiently answering 
>> > > the
>> > > question.
>> > >
>> > >
>> > > "Joe M." wrote:
>> > >
>> > > > Is it possible to have a macro that hides worksheets based upon 
>> > > > text
>> > > > contained or not contained in the worksheet name? Suppose i have 
>> > > > several
>> > > > worksheets but want to hide ony the ones that don't have the text 
>> > > > "HOLD" in
>> > > > the name;
>> > > >
>> > > > worksheet names:
>> > > > Data_HOLD
>> > > > Data Selection_HOLD
>> > > > etc....
>> > > > or maybe base it upon the WS tab color....
>> > > >
>> > > > Thanks,
>> > > > Joe M.
>> > > > 

0
Don
4/8/2010 6:03:48 PM
Reply:

Similar Artilces:

Macro warning with no macros
I have a workbook that when I try to open it I get the warning tellin me it contains macros and asking whether I want to Enable or Disabl them. I put no macros, no VB scripts, nothing at all in the workboo other than standard Excel formulas and some charts. I developed it i Excel 2002, SP-2, but have moved it back and forth between tw computers, the other which has Excel 97. Regardless of whether Enable or Disable or change the security settings so as not to get th warning, once the workbook is open even if I go t Tools-Macro-Macros... it lists no macros. How can I find out what's cau...

Why do legacy checkboxes freeze text fields in Word 2007?
If you use "Legacy Controls" checkboxes in Word 2007 and you have plain text or rich text fields, when you protect the document it will freeze you out of text fields after you select a checkbox. It only seems to do this with more than four or five check boxes and more than four or five text boxes. Help, anyone? Legacy fields require the document to be protected. Word 2007 content controls require it to be unprotected, thus the two are incompatible in the same document. -- <>>< ><<> ><<> <>>< ><<> <>...

Get the name of the version
Hi, When I used the Application.version it gave me a number like 10.0, how I can get the corresponding name of the the version like Excel 97, Excel 2002... ? Thank you. There is no property that returns the full name of the product, as far as I know. You could make your own little lookup/conversion routine as there are not that many versions. -- Jim Rech Excel MVP "Ben" <barben02@yahoo.com> wrote in message news:263001c41ca8$1d03faa0$3501280a@phx.gbl... | Hi, | | When I used the Application.version it gave me a number | like 10.0, how I can get the corresponding name...

Macro
Can anybody tell me how to kick off a macro automatically as file is opened? Regards ...

Macro
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: intel Hi, I'm thinking of buying Mac: Office 2008, but before I do I want to check that I will be able to download Scritpsmart collection of templates without any glitches: <http://www.bbc.co.uk/writersroom/scriptsmart/faq.shtml> Does anyone know if I can do this? Regards, SP. In article <ee98ff5.-1@webcrossing.caR9absDaxw>, StregaItalia@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.4 (Tiger) > Processor: intel > > Hi, > > I'm thinking of buying Mac: Of...

Run macro automatically.
How do I make a macro run automatically when a worksheet it is attached to is loaded? right click on the sheet tab>view code>left window worksheet>right window activate -- Don Guillett SalesAid Software donaldb@281.com "Excel macro" <Excel macro@discussions.microsoft.com> wrote in message news:DD7AF1E3-9263-4523-AC49-A43ABA1AB9D0@microsoft.com... > How do I make a macro run automatically when a worksheet it is attached to is > loaded? I am unable to find "activate " when I right click on worksheet. ( i assume that you are referring to the windo...

Terminal Server based Outlook 2007 printing hieroglyphics
We are running terminal services(Server 2008 R2) with Outlook 2007 installed (SP2). No other Office components are installed. When printing emails, (all other printing is fine), the text becomes compressed and looks like hieroglyphics. 1. I have tried removing all printer drivers and re-installing the drivers with no luck. 2. I have also applied the lastest patches and Service packs to the server and Outlook. 3. I have tried using different types of drivers with each printer ie. PS, MS, PCL5e, PCL6 etc with no luck. Any help would be appreciated as users are getting very fr...

Help with macro/and or formula?
Perhaps this is a silly question, but i just can't figure out how t format this worksheet. The problem is that a lot of the cells hav numbers in them with negative signs in the back instead of in the fron (ie. 23-) and i was wondering if anyone knew of a macro/formula i coul use to quickly fix this problem for all the cells. I would b extremely grateful. Thanks -- brefed1 ----------------------------------------------------------------------- brefed15's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3557 View this thread: http://www.excelforum.com/showthre...

Attached Toolbars Macros
Excel 2003 I have a custom tool bar, this tool bar has several items, each item is pointing to a VBA code. This tool bar is attached to the worksheet. I've copied this spreadsheet to several computers. After I copied the spreadsheet I decided to rename the spreadsheet, after I renamed the spreadsheet the Toolbar Item's macros were still pointing to the old name, I reasigned each tool bar item to the current spreadsheet, saved the spreadsheet and everything was working on my computer, but when I re-copied the new spreadsheet to other computers and I clicked on the Toolbar Item...

Hiding negative numbers
I know how to format cells and customize under the number tab, but is there a way for when a formula returns a negative number for it to have the cell be blank or equal zero? Thank you. One way: Format/Cells/Number/Custom General;;0;@ XL display formats have 4 fields. By default the first is for positive numbers, the second for negative numbers, the third for zero and the fourth for text. By leaving the negative number format blank, XL will not display negative numbers. In article <1535501c3fa4c$eccf8f70$a401280a@phx.gbl>, "Jay" <anonymous@discussions.microsof...

How to make worksheet name as variable?
In my workbook, some formulas are like this: =SUMPRODUCT(($E2<'sheet01'!$G$1:$G$500)*($F2>'sheet01'!$G$1:$G$500)*($C2='sheet01'!$E$1:$E$500)*($B2='sheet01'!$F$1:$F$500),'sheet01'!$J$1:$J$500) 'sheet01' is the name of one of my worksheets. It appears several time in the worksheet. When I want to make them refer to another worksheet, I have to change many instances of the name. Can I input the worksheet name into one of the cells, and the formulas get the name from the cell, so that I just have to change it once? Thanks in advance!! ...

Protected sheets and running macros
i have a sheet with a macro ran by a normal button at the top. Howeve when i protect the worksheet where ever i click on the sheet the macr executes. Can any one offer any advice on how to stop this? Thanks Robert -- Message posted from http://www.ExcelForum.com hi, i am not able to reproduce the problem, hence i may not be able t provide a panacea for that issue. here is what i suggest. i have a sheet that has a macro that is run when a control toolbo button (that is, not a form button) is clicked. this sheet is protected based on the user logged in. what i have don is to protect t...

Macro Freezes Reading Pane
I have a macro that Sends/Receives Tasks from Project Server into Outlook Tasks. Everything is working fine, except one weird thing that happens. I have the Timer set on the macro and it starts as soon as Outlook starts. The macro gets the tasks from ProjectServer every hour. As soon as the macro starts running the Reading pane freezes in the Inbox. If i stop the macro then Reading pane is back to normal. Can anyone please tell me if there is something I can do in VBA to fix this annoying issue. Thanks a lot ...

Macro to remove rows?
Hi, I receive thousands of rows of data from an extract that comes from a database. The data extract automatically generates page headers that need to be removed, and I would love to automate this process. The headers do have a pattern to them, but I'm not clever enough to figure out a good way to use that to write a macro. The first row of the header starts with hyphens ------------------------------- Then there's a variable number of rows of header data to delete followed by another row of hyphens ------------------------------- Then 2 additional rows that must be deleted. The nu...

Transferring Text
I need to be able to send data from one worksheet to another. Sheet 1 is the master and only sheet where data is entered. I have found out all cells have to be set to "Text" - which is not a problem. Sheet 1 Column A is Name Column B is Date of Birth Column C is the Surgery's name Is there a way that when the Surgery name is entered in say C5 the row's Name and Date of Birth can be sent to the next vacant row in say Sheet 3. Because of the number of surgeries, it is not possible to set them up to receive data from Sheet 1 - which is much easier, of course. I thought o...

What is CV text?
Can someone tell me what CV text is? Do you mean CSV, comma separated values? -- HTH RP "Tina" <Tina@discussions.microsoft.com> wrote in message news:ED97A150-9075-4251-8739-1E73F647527C@microsoft.com... > Can someone tell me what CV text is? And if you did mean CSV (comma separated values), then the name is pretty descriptive. But if you start a new test workbook and populate a bunch of cells with dummy data, then save it as a .CSV file. Then close excel. And open that .csv file in NotePad to see what it looks like. There are lots of programs that don't tal...

Calling on a macro within a macro!
Hey All!! Quick Question - How do you call up a macro within a current macro? I have one big macro and I need it to jump to several other macros when it runs! Does it matter where the other macros are stored or is it better to have them all in one module? Help appreciated Thnx! Hi Mellowe, '=============>> Public Sub Main() 'Your code Call One 'your code End Sub '<<============= '=============>> Public Sub One() MsgBox "Hi from One" End Sub '<<============= > Does it matter where the other macros are stored or ...

Change default "Show names from the:" option
Clicking the "To:" button in a new Outlook email message brings up the "Select Names" dialog box. This dialog displays the contents of contact databases such as My Outlook Address Book and Global Address List. Is there a way to change the default database selected in the "Show names from the:" line from the current Global Address List to the contacts in my Outlook Address Book? My version of Outlook connects with an Exchange server to acces mail, contacts, etc. Thanks for any suggestions, Kerry You probably meant to post your Outlook version so we coul...

shortcut keys to macros
Hi, Is it at all possible to assign shortcut keys to macros in Outlook? Thx, Hans ...

Data Text to Columns
I have a large column and would like to split it for the literal that says "Company Name" and then have the company name right next to it which is enterable. I tried using Data/Text to Columns, Fixed Width, sliding the arrow after Company Name: and it did not seem to split the column. I also tried putting an arrow out a ways so that there looked as though there were two defined fields and that didn't seem to work either. Am I approaching this the right way??? HELP!!! Thanks! Hi this is not possible in Excel. You have to use two columns for this -- Regards Frank Kabel Fr...

decimal point in worksheet
Y'all: I have a spreadsheet where I want to display a time as "min:sec". My worksheet formula for this is =INT(C2) & ":" & INT((C2-INT(C2))*60) No problem. Except that I want it to display like this: "30:03", not "30:3". How can I do this? e.g. Here is what I get: Time (minutes) Time (minutes:seconds) 30.050 30:3 Here is what I want: Time (minutes) Time (minutes:seconds) 30.050 30:03 I put the spreadsheet out on my website at http://webpages.charter.net/rwpatterson357/temp/test.xls thanks, russ Russ o...

Macro that password protects a sheet
I am attempting to create a macro that can open a protected sheet, change something, and then protect it again. I continue to have an issue with the macro not entering the password. Is this possible to do/fix? Thanks, Ryan ..open password="mypassword" -- Don Guillett SalesAid Software donaldb@281.com "Ryan" <Ryan@discussions.microsoft.com> wrote in message news:D4780ED8-CA1D-4284-97BC-3576160D998E@microsoft.com... > I am attempting to create a macro that can open a protected sheet, change > something, and then protect it again. I continue to have an iss...

help Unable to record Macro !!!!!!!
I want to record a macro in excel.But as soon as I click record Macro it says "unable to record" macro. Got no help in excel help.I do this same thing in word and it's working. Please help It's urgent for me !!!1 Have a look here http://groups.google.com/groups?as_epq=unable%20to%20record&as_ugroup=microsoft.public.excel.* -- Don Guillett SalesAid Software donaldb@281.com "ash" <anonymous@discussions.microsoft.com> wrote in message news:3e0b01c42ae5$45333e00$a401280a@phx.gbl... > I want to record a macro in excel.But as soon as I click > record...

Converting TOC to Text
I cut and paste text from a table of contents into a Word 2003 document. It is very lengthy and I'd rather not re-type the whole long list, since it would take a very long time. However, the TOC formatting is still in the document and I can't get rid of it. I can't include hyperlinks or change font color as a result. I've tried clearing all formatting without effect. Anyone know how to convert a TOC into text? Thanks! Ctrl+Shift+F9 will unlink it. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org &q...

Footer Macro?
Hi Months ago I read a Public Sub Macro that read the selection of a drop down list in a combo box and placed it in the center Footer at the same time it also placed the date in the right Footer and tme in the left footer. I have searched most of the regular sites including this one and cannot find it anywhere --- Can anyone help with my search. Any help much appreciated Cheers ---- Mully ...