VBA Group Rows & Columns

This tutorial will demonstrate how to group and ungroup rows and columns in VBA.

Group Rows or Columns

To group rows or columns apply the Group Method to the rows or columns:

Rows("3:5").Group

or

Columns("C:D").Group

Ungroup Rows or Columns

To ungroup the rows or columns, simply use the Ungroup Method:

Rows("3:5").Ungroup

or

Columns("C:D").Ungroup

Expand All “Grouped” Outline Levels

To expand all grouped outline levels, use this line of code:

ActiveSheet.Outline.ShowLevels RowLevels:=8, ColumnLevels:=8

To collapse all outline levels, use this line of code:

ActiveSheet.Outline.ShowLevels RowLevels:=1, ColumnLevels:=1