Excel VBA Hide and Unhide a Column or a Row

Last Updated: June 30, 2023
puneet-gogia-excel-champs

- Written by Puneet

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.

  1. Specify the column or the row using the range object.
  2. After that, use the entire column/row property to refer to the entire row or column.
  3. Next, use the hidden property.
  4. In the end, specify the true/false.

Following is the example to consider:

vba-hidden-property
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
hide-all-columns-and-rows

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