justanotheruser
Board Regular
- Joined
- Aug 14, 2010
- Messages
- 96
Hi all,
The following code is used to show/hide columns based on the value of cell E15. I need to apply the following logic to unhide all the columns from E:P and then hide specific columns depending on E15's value to 20 sheets.
So for example, if E15 was 2011_CYF1, then columns E to P should be unhidden on the sheet called 1 P&L Entity, and then columns E:F should be hidden. However, is it possible to get this code to do it instead of just for one sheet, "1 P&L Entity" to a list of sheets so that I don't need multiple lines of code where the sheet name has changed? i.e. Columns E to P should be unhidden on sheets "1 P&L Entity", "2 Balance", "Sheet3", "Sheet 4" etc.
Unfortunately I can't do it for all the sheets in the workbook as some of them shouldn't have the columns hidden, so it is possible to put all the sheet names in one argument (is that the right word?) of code, instead of copying down multiple times and just changing the sheet name.
This is what I'd rather not do:
Thanks in advance for your help!
The following code is used to show/hide columns based on the value of cell E15. I need to apply the following logic to unhide all the columns from E:P and then hide specific columns depending on E15's value to 20 sheets.
Code:
If Target.Address(False, False) = "E15" Then
If Target.Value Like "####_CYF1" Then
Sheets("1 P&L Entity").Columns("E:P").EntireColumn.Hidden = False
Sheets("1 P&L Entity").Columns("E:F").Hidden = True
ElseIf Target.Value Like "####_CYF2" Then
Sheets("1 P&L Entity").Columns("E:P").EntireColumn.Hidden = False
Sheets("1 P&L Entity").Columns("E:J").EntireColumn.Hidden = True
ElseIf Target.Value Like "####_CYF3" Then
Sheets("1 P&L Entity").Columns("E:P").EntireColumn.Hidden = False
Sheets("1 P&L Entity").Columns("E:J").EntireColumn.Hidden = True
ElseIf Target.Value Like "####_CYF4" Then
Sheets("1 P&L Entity").Columns("E:P").EntireColumn.Hidden = False
Sheets("1 P&L Entity").Columns("E:M").EntireColumn.Hidden = True
Else
Sheets("1 P&L Entity").Columns("E:P").EntireColumn.Hidden = False
End If
End If
So for example, if E15 was 2011_CYF1, then columns E to P should be unhidden on the sheet called 1 P&L Entity, and then columns E:F should be hidden. However, is it possible to get this code to do it instead of just for one sheet, "1 P&L Entity" to a list of sheets so that I don't need multiple lines of code where the sheet name has changed? i.e. Columns E to P should be unhidden on sheets "1 P&L Entity", "2 Balance", "Sheet3", "Sheet 4" etc.
Unfortunately I can't do it for all the sheets in the workbook as some of them shouldn't have the columns hidden, so it is possible to put all the sheet names in one argument (is that the right word?) of code, instead of copying down multiple times and just changing the sheet name.
This is what I'd rather not do:
Code:
If Target.Value Like "####_CYF1" Then
Sheets("1 P&L Entity").Columns("E:P").EntireColumn.Hidden = False
Sheets("1 P&L Entity").Columns("E:F").Hidden = True
Sheets("2 Balance").Columns("E:P").EntireColumn.Hidden = False
Sheets("2 Balance").Columns("E:F").Hidden = True
Sheets("Sheet3").Columns("E:P").EntireColumn.Hidden = False
Sheets("Sheet3").Columns("E:F").Hidden = True
Sheets("Sheet4").Columns("E:P").EntireColumn.Hidden = False
Sheets("Sheet4").Columns("E:F").Hidden = True
Thanks in advance for your help!