TL;DR โ
Columns("B:D").Groupfolds columns B through D behind a horizontal outline across the top of the sheet โ the same fold as grouping rows, turned ninety degrees. Two column-specific things trip people: the collapse button lands to the right of the group by default (Outline.SummaryColumn), and grouping only works on whole columns โ a partial range does not group the columns.
Sub GroupMonthColumns()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Report")
ws.Cells.ClearOutline ' start flat so a re-run does not stack levels
ws.Outline.SummaryColumn = xlSummaryOnLeft ' button attaches to the totals column on the LEFT
ws.Columns("C:N").Group ' fold the 12 month columns behind the total in B
ws.Outline.ShowLevels ColumnLevels:=1 ' collapse columns only, leaving row groups alone
End Sub
Grouping columns is grouping rows on the other axis: the same .Group verb, the same
outline object underneath, the same collapse-by-level rule. What changes with columns
is the side the button defaults to and the fact that "a column" means the whole column โ the exact echo of
the "insert the EntireColumn, never a partial range" rule from structural edits.
What you'll learn
- The mental model โ a horizontal fold, the row outline rotated ninety degrees
- The summary-column trap โ why the button lands on the right, and how to move it left
- Why grouping needs whole columns, and what a partial range does instead
- How
ShowLevelscollapses columns on their own axis, independent of row groups - Why grouping a column is not the same as hiding it or setting its width
The mental model: a horizontal fold
Columns("B:D").Group builds an outline bar across the top of the sheet, with a โ button that folds
columns B through D out of view and a + that brings them back. It is the row outline rotated ninety
degrees โ instead of folding blocks of rows into a margin on the left, you fold blocks of columns into a bar
on top.
Everything true of grouping rows is true here: the columns are folded, not hidden
in the .Hidden sense and not deleted; the outline organises them into levels up to eight deep; and you
collapse by level rather than by touching .Hidden. This article is about the two things that are
specifically different when the axis is columns.
The summary-column trap: the button lands on the right
Group columns B to D and the collapse button appears not on the group but to the right of it, over
column E. That is Worksheet.Outline.SummaryColumn defaulting to xlSummaryOnRight: Excel assumes your
summary or total column sits to the right of the detail it summarises.
That is the mirror of the summary-row default, and it is wrong for the same reason in a common layout โ a totals column placed on the left, before a run of monthly detail:
ws.Outline.SummaryColumn = xlSummaryOnLeft ' button attaches to the total column on the LEFT
ws.Columns("C:N").Group ' total is column B, detail is columns C-N
Leave it on the default and the + floats off to the right of your last month, detached from the total in
column B that the reader is looking at. SummaryColumn is a sheet-level setting โ set it once, before
you build the outline, to match which side your totals sit on. Note the constant spelling differs from the
row version: columns use xlSummaryOnLeft / xlSummaryOnRight, rows use xlSummaryAbove / xlSummaryBelow.
Group whole columns, never a partial range
Grouping columns only means anything when you name whole columns:
ws.Columns("B:D").Group ' folds three whole columns
ws.Range("B:D").EntireColumn.Group ' identical, spelled out
Hand .Group a partial range and it does not fold the columns:
ws.Range("B2:D2").Group ' does NOT group columns B-D
A range that is not whole columns cannot become a column group โ depending on the sheet you get a run-time
error or a grouping you did not mean. This is the same rule that governs inserting and deleting: to act on a
column, name a column (Columns(...) or .EntireColumn), the same discipline as
inserting the EntireColumn. If you have a header cell and need its column, widen
to the whole column first:
ws.Rows(1).Find("Q1", LookAt:=xlWhole).EntireColumn.Group ' find the header, group its whole column
ShowLevels collapses columns on their own axis
The outline tracks rows and columns as two independent axes, which is why ShowLevels takes two arguments:
ws.Outline.ShowLevels ColumnLevels:=1 ' collapse the COLUMN outline to level 1
ws.Outline.ShowLevels RowLevels:=2, ColumnLevels:=1 ' set both axes in one call
Passing ColumnLevels alone folds the columns while leaving any row grouping exactly where it was โ the two
outlines do not interfere. This is the payoff of driving the outline object instead of
hiding things by hand: you address one axis without disturbing the other, and the buttons stay truthful.
Grouping is not hiding, and not width
Because a collapsed column group looks like a hidden column, it is easy to conflate three different tools. They are not interchangeable:
- Group builds a reversible, level-aware outline with buttons the reader can click โ right when the columns are detail you fold away and open back up.
- Hide (
.Hidden = True) is a flat on/off state with no outline and no button โ right when you simply want a column gone from view. - Width (
.ColumnWidth = 0) is a size, not a visibility state โ a different intent again.
Reach for grouping when you want a foldable section the reader controls; reach for hiding when you want a column plainly out of the way. Using one where you meant another is the bug โ a grouped column the reader can re-open when you wanted it firmly hidden, or a hidden column with none of the outline structure you were after.
How ExcelMaster helps
Grouping columns is one line that hides three decisions โ which side the collapse button belongs on for
your layout, whether you handed it whole columns or a partial range that silently does nothing, and whether
you meant a foldable group at all rather than a plain hide โ and getting any of them wrong fails without an
error: a button floating right of a left-hand total, a .Group call that grouped nothing, or a reader
re-opening a column you wanted hidden.
ExcelMaster lets you say what you
want โ "fold the twelve month columns behind the totals column, button on the left, collapsed" โ and it sets
SummaryColumn to match, groups the whole columns (never a partial range), collapses with ColumnLevels so
row groups stay put, and reaches for hiding instead when that is what you actually meant. You keep the
workbook and the code.
Frequently asked questions
How do I group columns in VBA?
Call .Group on whole columns: Columns("B:D").Group folds columns B through D behind a horizontal outline
bar with a collapse button along the top. Qualify the sheet โ
ThisWorkbook.Worksheets("Report").Columns("B:D").Group โ so it does not depend on the active sheet. The
columns are folded, not hidden or deleted.
Why is the collapse button on the right of my grouped columns?
Because Worksheet.Outline.SummaryColumn defaults to xlSummaryOnRight, which assumes your total column is
to the right of the detail. If your totals column is on the left, set
ws.Outline.SummaryColumn = xlSummaryOnLeft before grouping so the button attaches to it.
Why does grouping do nothing when I pass a range like B2:D2?
Because a partial range is not whole columns, and only whole columns can form a column group. Use
Columns("B:D").Group or Range("B:D").EntireColumn.Group. To group the column a header sits in, find it
and widen to the whole column: Rows(1).Find("Q1", LookAt:=xlWhole).EntireColumn.Group.
How do I collapse grouped columns without affecting grouped rows?
Pass only the column axis to ShowLevels: ws.Outline.ShowLevels ColumnLevels:=1 collapses the column
outline while leaving any row grouping untouched. The outline tracks rows and columns as independent axes,
so setting one does not disturb the other.
Is grouping a column the same as hiding it?
No. Grouping builds a reversible outline with a button the reader can click to fold and unfold the columns;
hiding (.Hidden = True) is a flat on/off state with no outline or button. Use grouping for a foldable
section the reader controls, and hiding when you simply want the column out of view.
Tested in
Tested in: Excel 365 (Windows 11), VBA 7.1 โ last verified 2026-09-16.
Related guides: VBA Group Rows ยท VBA Outline ยท VBA Hide Columns ยท VBA Column Width ยท VBA Insert Columns
