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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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,213,531
Messages
6,114,167
Members
448,554
Latest member
Gleisner2

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