VBA Hidden Property
To hide/unhide a column or a row in Excel using VBA, you can use the “Hidden” property. To use this property, you need to specify the column, or the row using the range object and then specify the TRUE/FALSE.
- Specify the column or the row using the range object.
- After that, use the entire column/row property to refer to the entire row or column.
- Next, use the hidden property.
- In the end, specify the true/false.
Following is the example to consider:
Sub vba_hide_row_columns()
'hide the column A
Range("A:A").EntireColumn.Hidden = True
'hide the row 1
Range("1:1").EntireRow.Hidden = True
End Sub
In the above code, we have used the hidden property to hide columns A and row 1. And here is the code for unhiding them back.
Sub vba_hide_row_columns()
'unhide the column A
Range("A:A").EntireColumn.Hidden = False
'unhide the row 1
Range("1:1").EntireRow.Hidden = False
End Sub
VBA Hide/Unhide Multiple Rows and Columns
Sub vba_hide_row_columns()
'hide the column A to c
Range("A:C").EntireColumn.Hidden = True
'hide the row 1 to 4
Range("1:4").EntireRow.Hidden = True
End Sub
And in the same way, if you want to unhide multiple rows and columns.
Sub vba_hide_row_columns()
'hide the column A to c
Range("A:C").EntireColumn.Hidden = False
'hide the row 1 to 4
Range("1:4").EntireRow.Hidden = False
End Sub
Hide All Columns and Rows
Sub vba_hide_row_columns()
'hide the column A
Columns.EntireColumn.Hidden = True
'hide the row 1
Rows.EntireRow.Hidden = True
End Sub
Unhide All Columns and Rows
Sub vba_hide_row_columns()
'unhide all the columns
Columns.EntireColumn.Hidden = False
'unhide all the rows
Rows.EntireRow.Hidden = False
End Sub
Hide/Unhide Columns and Rows in Another Worksheet
Sub vba_hide_row_columns()
'hide all columns in the sheet 1
Worksheets("Sheet1").Columns.EntireColumn.Hidden = False
'hide all rows in the sheet 1
Worksheets("Sheet1").Rows.EntireRow.Hidden = False
End Sub
What is VBA
Related Tutorials
- Count Rows using VBA in Excel
- Excel VBA Font (Color, Size, Type, and Bold)
- Excel VBA Range – Working with Range and Cells
- Apply Borders on a Cell using VBA in Excel
- Find Last Row, Column, and Cell using VBA in Excel
- Insert a Row using VBA in Excel
- Merge Cells in Excel using a VBA Code
- Select a Range/Cell using VBA in Excel
- SELECT ALL the Cells in a Worksheet using VBA
- ActiveCell in VBA in Excel
- Special Cells Method in VBA in Excel
- UsedRange Property in VBA in Excel
- VBA AutoFit (Rows, Column, or the Entire Worksheet)
- VBA ClearContents (from a Cell, Range, or Entire Worksheet)
- VBA Copy Range to Another Sheet + Workbook
- VBA Enter Value in a Cell (Set, Get and Change)
- VBA Insert Column (Single and Multiple)
- VBA Named Range | (Static + from Selection + Dynamic)
- VBA Range Offset
- VBA Sort Range | (Descending, Multiple Columns, Sort Orientation
- VBA Wrap Text (Cell, Range, and Entire Worksheet)
- VBA Check IF a Cell is Empty + Multiple Cells