Unload/Unhide Sheet Based on Name

manthony

New Member
Joined
Dec 5, 2016
Messages
40
Hi, I am trying to unhide a very hidden worksheet based on a name picked from the drop down list. I am getting a Run-time error 91 Object variable or with block variable not set on the "If ws = Worksheets("Administrator").Range("B9").Value Then" line. Any ideas on how to fix this?

Code:

Dim ws As Worksheet

If ws = Worksheets("Admin").Range("B9").Value Then
ws.Visible = True
End If

Call Macro1


End Sub

Thanks for the help.

Mike
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
try this:
Code:
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets


If ws.Name = Worksheets("Sheet1").Range("B9").Value Then
ws.Visible = True
Call Macro1
Exit For
End If
Next ws
 
Upvote 0
You could just use this single line which will just do nothing if the tab is visible:

Code:
Sheets(CStr(Worksheets("Admin").Range("B9"))).Visible = xlSheetVisible

Robert
 
Last edited:
Upvote 0
Thank you both. The code worked perfectly.



Hi, I am trying to unhide a very hidden worksheet based on a name picked from the drop down list. I am getting a Run-time error 91 Object variable or with block variable not set on the "If ws = Worksheets("Administrator").Range("B9").Value Then" line. Any ideas on how to fix this?

Code:

Dim ws As Worksheet

If ws = Worksheets("Admin").Range("B9").Value Then
ws.Visible = True
End If

Call Macro1


End Sub

Thanks for the help.

Mike
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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