Macro to Unhide sheets based on input box text

Lehcar

New Member
Joined
Jul 8, 2013
Messages
4
Morning,

I am a novice to VBA, anything I have ever written is self-taught so be warned!

I have searched and tried numerous ways of writing VBA code to achieve this but to no avail.

I have an inherited 28 spreadsheets each with hundreds of sheet tabs some hidden and some not.

Every month I have to find any sheets containing part of the months name and unhide it.

So sheet name examples "RAMS rejected -MAY", "RAMS rejected - JUNE", "Open Permits - MAY", "Open Permits - JUN"

I want an input box to appear to ask them for first 3 letters of month name - i.e. "JUN"
and then using this input search all .xlhidden sheets (there are no 'veryhidden' ones) and make them xlvisible.

So in the above example it would unhide: "RAMS rejected - JUNE", "Open Permits - JUN"
and leave the other two hidden

I can't even start to give examples of the codes tried as I have tried so many that my brain is now mush :) !!

Thank you in advance.

Oh yes - I am using Excel 2013 in case this matters.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
This should do the job for you..
Code:
Sub UnhideSheets()
Dim sh As Worksheet
Application.ScreenUpdating = False
Dim Search As String
Search = InputBox("Enter Search Criteria", "Sheet Finder")
For Each sh In ActiveWorkbook.Sheets
If InStr(1, sh.Name, Search) > 0 Then sh.Visible = xlSheetVisible
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hi, and welcome to the forum. :)

Try something like this:

Code:
Sub UnhideThem()
   Dim sMonth As String
   Dim sht As Object
   sMonth = InputBox("Enter first three letters of month to unhide")
   If Len(sMonth) > 0 Then
      For Each sht In ActiveWorkbook.Sheets
         If sht.Visible = xlSheetHidden Then
            If UCase$(sht.Name) Like "*" & Left$(sMonth, 3) & "*" Then sht.Visible = xlSheetVisible
         End If
      Next sht
   End If
End Sub
 
Upvote 0
Thank you slinky and RoryA - both worked a treat - now for my lesson of the day ... try and understand what you both wrote so I can work out where I was going wrong so I learn for the future.

Sorry it took me so long to test - bloomin' meetings!!

Cheers
:biggrin:
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,842
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top