Unhiding a Specific Number of Worksheets Based On A Cell Value

NoviceMacroMan

New Member
Joined
Jun 26, 2013
Messages
6
Hello everybody! :) I have been attempting to cobble together code from different forums for the past several hours to make a macro to unhide a specific number of worksheets based on a cell value, and have failed miserably thus far. To that end, I thought I would try appealing to you nice folks for assistance before I lose it. Here are the specifics of what I have going on:

Microsoft Excel 2010
Workbook Name: TASERR Model - 06-26-13.xlsm

In this workbook, I have a worksheet called "Input". In cell C21 of that worksheet, workbook users will fill in a number between 1 and 50 (I have the value for that cell limited to those numbers through data validation). Based on the value in that cell (C21), I want to make a macro to unhide that specific number of hidden worksheets. I have 50 hidden worksheets which are named "Route (1)", "Route (2)", "Route (3)", etc.. If the value in cell C21 is 7, I want the worksheets named "Route (1)", "Route (2)", "Route (3)", "Route (4)", "Route (5)", "Route (6)", and "Route (7)" to unhide. If the value in cell C21 is 3, I want the worksheets named "Route (1)", "Route (2)", and "Route (3)" to unhide. I'm sure y'all can see the functionality I'm going for at this point.

I'd be extremely grateful for any help on this one. Thank you kindly (in advance)!
 
s-duggie,

Welcome to MrExcel.

On the face of it there is glaring omission in my original code and I am surprised that the original poster, NMM did not have a similar issue.
The Worksheet Change event code needs to ensure that the Target address is correct as it does in the Selection+Change code.

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Target.Address = "$C$14" Then Exit Sub
If Target.Cells.Count > 2 Then Exit Sub
On Error GoTo ErrOut
If OldNum < 2 Then OldNum = 2
If OldNum > Target Then
For c = Target + 1 To OldNum
Sheets("Additional (" & c & ")").Visible = False
Next c
Else
For c = OldNum To Target
Sheets("Additional (" & c & ")").Visible = True
Next c
End If
ErrOut:
On Error GoTo 0
End Sub

Hope that helps.
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,223,250
Messages
6,171,036
Members
452,374
Latest member
keccles

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