Hiding Sheets

ArbiterWolf

New Member
Joined
Jan 15, 2022
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
I have a excel workbook with about 60 sheets. I have a sheet that you input page numbers into and it separates the info onto the different sheets depending on the different info tied to particular page numbers. So I have a "Total" qty # of pages on every sheet. I would like to have all the sheets hidden until the total is >0.

So I currently have this code on the sheet you input the info on.

Sub Worksheet_Change(ByVal Target As Range)
Application.Volatile
If Sheet5.Range("C58").Value > 0 Then
Sheet5.Visible = True
Else
Sheet5.Visible = False
End If
End Sub

And it works exactly how I want it but what I want to know is if there is a easier way to apply this code to all the sheets? Or do I have to copy this code 60+ times for each individual sheet?
So the "total" cell is in the same cell for the first 20 sheets then in the same for the rest. 1-20 its C58 21-60 its E60.
 
the triggersheet and the triggercell were indeed something you had to adapt to your situation.
You never said what the real trigger was, so that was an assumption.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
The following was going to be what I suggested:

VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'
    Dim CodeNameNumber          As Long
    Dim CodeNameSheetChanged    As String
'
    CodeNameSheetChanged = Sheets(Sh.Name).CodeName
    CodeNameNumber = Val(Right(CodeNameSheetChanged, Len(CodeNameSheetChanged) - 5))
'
        If CodeNameNumber < 21 Then
            If Sheets(Sh.Name).Range("C58").Value > 0 Then
                Sheets(Sh.Name).Visible = True
            Else
                Sheets(Sh.Name).Visible = xlSheetVeryHidden
            End If
        Else
            If Sheets(Sh.Name).Range("E60").Value > 0 Then
                Sheets(Sh.Name).Visible = True
            Else
                Sheets(Sh.Name).Visible = xlSheetVeryHidden
            End If
        End If
End Sub

That was assuming that CodeNames of sheets were being looked at & the codeNames of the sheets are all Sheetx.

But the OP is satisfied, so no reason to post it. :rolleyes:
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,584
Messages
6,125,670
Members
449,248
Latest member
wayneho98

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