Hiding Columns with Dynamic/Changing Tab Names

nutrastat

Board Regular
Joined
Nov 1, 2008
Messages
57
PROBLEM: We need to hide several columns, on several sheets, based on a cell saying either TRUE or FALSE. But this is not so easy when the tab names (i.e. sheet names) can change, meaning that the formula for hiding these columns must be 'dynamic' also.

In the spreadsheet we have formulas calling on data from different sheets. Unfortunately, as these sheet names (i.e. tab names) can change e.g. going from 'Accommodation' to 'HouseKeeping', we have made the formulas indirected so that the formulas still work after such name changes.

We have one cell [Named: WK5_TRUE_FALSE] that changes to TRUE when there is a 5-week month and FALSE when there is a 4-week month.

We therefore need, when WK5_TRUE_FALSE = FALSE, to hide columns W,X, Y & Z on sheets Accommodation, Bars, Garbage & Galley, bearing in mind that Accommodation could be renamed Housekeeping.

Is this possible?

Any help you can give would be much appreciated as this is definately outside of my experience/capabilities.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Assuming there is somewhere a cell name: WK5_TRUE_FALSE
In the sheet's code where this cell is placed installed next code
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    If (Target.Address = Range("WK5_TRUE_FALSE").Address) Then HIDE_COLUMN (Target.Value)
End Sub
in a module placed next code
Code:
Option Explicit
Sub HIDE_COLUMN(FLAG_COL As Boolean)
Dim SH As Object
    For Each SH In Sheets
    Select Case SH.Name
            Case "Accommodation", "Housekeeping", "Bars", "Garbage", "Galley"
                Sheets(SH.Name).Columns("W:Z").EntireColumn.Hidden = FLAG_COL
        End Select
    Next SH
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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