VBA Group Rows & Columns

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on January 10, 2022

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

 

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples