Hide / Unhide Columns & Rows

This tutorial will demonstrate how to hide and unhide rows and columns using VBA.

Hide Columns or Rows

To hide columns or rows set the Hidden Property of the Columns or Rows Objects to TRUE:

Hide Columns

There are several ways to refer to a column in VBA. First you can use the Columns Object:

Columns("B:B").Hidden = True

or you can use the EntireColumn Property of the Range or Cells Objects:

Range("B4").EntireColumn.Hidden = True

or

Cells(4,2).EntireColumn.Hidden = True

Hide Rows

Similarly, you can use the Rows Object to refer to rows:

Rows("2:2").Hidden = True

or you can use the EntireRow Property of the Range or Cells Objects:

Range("B2").EntireRow.Hidden = True

or

Cells(2,2).EntireRow.Hidden = True

Unhide Columns or Rows

To unhide columns or rows, simply set the Hidden Property to FALSE:

Columns("B:B").Hidden = False

or

Rows("2:2").Hidden = False

Unhide All Columns or Rows

To unhide all columns in a worksheet, use Columns or Cells to reference all columns:

Columns.EntireColumn.Hidden = False

or

Cells.EntireColumn.Hidden = False

Similarily to unhide all rows in a worksheet use Rows or Cells to reference all rows:

Rows.EntireRow.Hidden = False

or

Cells.EntireRow.Hidden = False