lemmorsojedirdam16
New Member
- Joined
- Mar 16, 2018
- Messages
- 13
Hi All... I am new to vba and still wanted to learn. I need your help to solve my problem. I would like to know how I am able to add more task on below vba to hide rows and columns of multiple sheet based on a cell value of another sheet.
Let say: On Sheet1, If I enter a value of 7 (this is number of days) and etc on cell B8, the rows 10 to 20 of sheet 2, sheet 3, sheet 4 and so on will be hidden and the columns AB:CF of sheet1 will be hidden.
I hope someone will help me. Thanks in advance
Let say: On Sheet1, If I enter a value of 7 (this is number of days) and etc on cell B8, the rows 10 to 20 of sheet 2, sheet 3, sheet 4 and so on will be hidden and the columns AB:CF of sheet1 will be hidden.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim aNames
Dim i As Long
Const sNames As String = "Sheet2, Sheet3, Sheet4, Sheet5" '<- Names of your sheets (can add more)
Const RowCell As String = "B8" '<- Cell you enter no. of rows into
If Target.Address(0, 0) = RowCell Then
aNames = Split(sNames, ", ")
Application.ScreenUpdating = False
For i = 0 To UBound(aNames)
With Sheets(aNames(i))
.Rows("44:115").Hidden = False
.Columns("AE:CF").Hidden = False
If Target.Value = "7" Then
.Rows("44:115").Hidden = True
.Columns("AE:CF").Hidden = True
End If
.Columns("S:CF").Hidden = False
.Rows("28:115").Hidden = False
If Target.Value = "3" Then
.Rows("28:115").Hidden = True
.Columns("S:CF").Hidden = True
End If
.Columns("AK:CF").Hidden = False
.Rows("52:115").Hidden = False
If Target.Value = "9" Then
.Rows("52:115").Hidden = True
.Columns("AK:CF").Hidden = True
End If
' <--- I can add more similar task
End With
Next i
Application.ScreenUpdating = True
End If
End Sub
I hope someone will help me. Thanks in advance
Last edited by a moderator: