VBA: Unhide Sheet depending on cell value

unknownymous

Board Regular
Joined
Sep 19, 2017
Messages
249
Office Version
  1. 2016
Platform
  1. Windows
Hello Gurus,

I am trying to create a macro where in if the cell value in the MAIN sheet matches one with the hidden sheet name, macro will unhide it.

By the way, those Data x Sheetswhere hidden because there's too many.
Example: In the MAIN sheet, if cell Value in A1 is "DATA 1" then it should unhide the tab with sheet name as "DATA 1"

' = = = This one is not working
Sub UnhideSheet()

Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "MAIN" Then
If sh.Range("A1").Value = "DATA 1" Then sh.Visible = True
If sh.Range("A1").Value = "DATA 2" Then sh.Visible = True
If sh.Range("A1").Value = "DATA 3" Then sh.Visible = True
'Add more
'Add more
'Add more

End If
Next sh
End Sub

= = = =

Appreciate the help.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
only based in A1 Value in MAIN Sheet?

if A1 Value DATA 1 , then unhide DATA 1 sheet?

still need to check a2 a3 ?

VBA Code:
Sub TEST()
Dim ws As Worksheet
Set ws = Sheets("MAIN")
On Error Resume Next

shtname = ws.Range("a1").Value
Worksheets(shtname).Visible = True


End Sub
 
Last edited:
Upvote 0
only based in A1 Value in MAIN Sheet?

if A1 Value DATA 1 , then unhide DATA 1 sheet?

still need to check a2 a3 ?

VBA Code:
Sub TEST()
Dim ws As Worksheet
Set ws = Sheets("MAIN")
On Error Resume Next

shtname = ws.Range("a1").Value
Worksheets(shtname).Visible = True


End Sub
All good now. Thanks!
 
Upvote 0
pls try this code

Sub UnhideSheet()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
If sh.Name <> "MAIN" Then
Select Case sh.Range("A1").Value
Case "DATA 1", "DATA 2", "DATA 3"
sh.Visible = xlSheetVisible
Exit For
' Add more conditions
End Select
End If
Next sh
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,102
Messages
6,123,099
Members
449,096
Latest member
provoking

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