Hide sheets based on a cell value in a list

rob_sheeds

Board Regular
Joined
Dec 9, 2010
Messages
57
I have a list with account numbers. Each account has a sheet. If the account balance is zero, I would like to hide that sheet. Need help with the code.
Account Balance
12345 -
This corresponding sheet "12345" would need to be hidden and then move onto the next account in the list.
I can name ranges and manipulate code just cant write it that well.
Thanks in advance!!!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Try:
Code:
Sub hd()
Dim ws As Worksheet
'On Error Resume Next
For Each ws In Worksheets
For i = 2 To Sheets.Count
If ws.Name = Range("A" & i) Then
    If Range("B" & i) = 0 Then
        If ws.Visible = xlSheetVeryHidden Then
            ws.Visible = xlSheetVisible
        Else
            ws.Visible = xlSheetVeryHidden
        End If
    Else
        If ws.Visible = xlSheetVeryHidden Then ws.Visible = xlSheetVisible
    End If
End If
Next
Next
End Sub
Col A - Account Name 'Change to suit
Col B - Account Balance 'Change to suit
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,459
Members
452,915
Latest member
hannnahheileen

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