Harshil Mehta
Board Regular
- Joined
- May 14, 2020
- Messages
- 85
- Office Version
- 2013
- Platform
- Windows
The code dynamically hides rows & columns. I want to apply this code in one go to multiple sheets.
Sheets Names are based on cell value which means if the value in the cell changes, sheet name also changes.
I am new to VBA coding, would be thankful if anyone could help me out with this.
Sub Hide_Rows_Columns()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets(Array(Sheets(2), Sheets(3), Sheets(4)))
With Range("B:B")
Range(.Cells(Rows.Count, 2), .Cells(Rows.Count, 2).End(xlUp).Offset(2, 0)).EntireRow.Hidden = True
End With
With Range("10:10")
Range(.Cells(1, .Columns.Count), .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 2)).EntireColumn.Hidden = True
End With
Next
End Sub
Sheets Names are based on cell value which means if the value in the cell changes, sheet name also changes.
I am new to VBA coding, would be thankful if anyone could help me out with this.
VBA Code:
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets(Array(Sheets(2), Sheets(3), Sheets(4)))
With Range("B:B")
Range(.Cells(Rows.Count, 2), .Cells(Rows.Count, 2).End(xlUp).Offset(2, 0)).EntireRow.Hidden = True
End With
With Range("10:10")
Range(.Cells(1, .Columns.Count), .Cells(1, .Columns.Count).End(xlToLeft).Offset(0, 2)).EntireColumn.Hidden = True
End With
Next
End Sub