Hide Sheets Based On Value

Hammer18

New Member
Joined
Dec 21, 2023
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello, is there VBA that can look at a specific cell (or multiple cells) on each sheet and hide that sheet if the value (or all values in the case of multiple cells) is 0? The cell reference is different on each tab and can change based on data that is added or removed. Each sheet name are different account numbers. Thank you
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Please try the following on a copy of your workbook. It assumes you do have a sheet called "TB" that will not be assessed, and therefore always visible.

VBA Code:
Option Explicit
Sub Hammer18()
    Dim ws As Worksheet, c As Range, i As Long
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "TB" Then
            i = 0
            For Each c In ws.UsedRange.SpecialCells(xlCellTypeConstants)
                If c = "Balance" Then
                    If c.Offset(0, -1) <> 0 Then i = i + 1
                End If
            Next c
            If i > 0 Then ws.Visible = True Else ws.Visible = False
        End If
    Next ws
End Sub
 
Upvote 0
Solution
That worked on my test worksheet. I should be able to tweak it to make it work on the working copy. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,988
Members
449,093
Latest member
Mr Hughes

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