Sub topic 6
Choosing a style and style options
This chapter assumes you can already create a table with Ctrl+T, that the table has a header row, and that you know the Ribbon. It covers the formatting layer of a table. Styles change how a table looks. They never change the values, formulas, or behavior underneath.
What a table style is
A table style is a named set of formatting rules. Each rule targets one part of the table: the header row, the total row, the first or last column, odd and even stripes, and so on. When you apply a style, Excel paints those parts from the rules. It does not write formatting into each cell.
That distinction explains most of the behavior you will see:
- New rows pick up the stripe pattern automatically, because the style is attached to the table and not to cells.
- Sorting or filtering does not scramble the stripes. They are recalculated from the visible row order.
- Colors come from the workbook theme. If you switch the theme on the Page Layout tab, every table recolors.
- Direct formatting wins. If you fill a cell yellow by hand, that fill stays on top of the style, even after you change styles.
A new table gets Table Style Medium 2 (blue header, light blue stripes) unless you have set another default.
Applying a style
Click any cell in the table. The contextual Table Design tab appears on the Ribbon. In older versions it is called Design. Open the Table Styles gallery and click a thumbnail. Hovering over a thumbnail shows a live preview without committing.
The gallery has three groups, which are also the families of built-in style names:
| Family | Built-in names | Character |
|---|---|---|
| Light | TableStyleLight1 to TableStyleLight21 | Thin lines or pale fills. Prints well and uses little ink. |
| Medium | TableStyleMedium1 to TableStyleMedium28 | Solid colored header with banding. The most common choice. |
| Dark | TableStyleDark1 to TableStyleDark11 | Heavy fills with light text. Best on screen. |
The number in a name is the position in its family, so Table Style Medium 2 in the gallery is TableStyleMedium2 in VBA.
Clearing a style
Open the gallery and choose Clear at the bottom. The table keeps its behavior (filter buttons, structured references, expansion) but has no visible formatting. This is useful when you want to format the table entirely by hand, or when you only need the table for its formulas.
Changing the default
Right-click a thumbnail and choose Set As Default. Tables you create afterward in this workbook use that style. The default is stored per workbook, not globally for Excel.
Table style options
The Table Style Options group on the Table Design tab holds checkboxes. Each one turns a stylable part of the table on or off.
| Option | Effect | VBA property on `ListObject` |
|---|---|---|
| Header Row | Shows or hides the header row. | `ShowHeaders` |
| Total Row | Adds or removes the total row. | `ShowTotals` |
| First Column | Emphasizes the leftmost column, usually bold. | `ShowTableStyleFirstColumn` |
| Last Column | Emphasizes the rightmost column. | `ShowTableStyleLastColumn` |
| Banded Rows | Alternating row shading. | `ShowTableStyleRowStripes` |
| Banded Columns | Alternating column shading. | `ShowTableStyleColumnStripes` |
| Filter Button | Shows the drop-down arrows in the header. | `ShowAutoFilterDropDown` |
Two of these are not purely cosmetic.
Header Row. Turning it off hides the header cells from view. The header names still exist, so structured references such as SalesTable[Amount] keep working. Excel temporarily shows the column names in place of the column letters while you are inside the table. Hiding the header is not the same as deleting the data, and the filter buttons go with it.
Total Row. Ticking it inserts a new row below the data, with formulas of the SUBTOTAL kind. The total row is covered in its own chapter. Here, only note that it is a style option you can toggle as easily as stripes.
Whether an option has a visible effect depends on the style. A style that defines no column stripes shows nothing when you tick Banded Columns. If an option seems to do nothing, check that first.
How the parts combine
When several rules overlap, the more specific one wins. A cell in the header row of the first column gets the header row formatting, not the first-column formatting, because the header is more specific. The diagram shows the order Excel resolves formatting for one cell.
Creating a custom style
When none of the built-in styles fits a house look, build your own.
- Open the Table Styles gallery and choose New Table Style.
- Enter a name. Use something descriptive, such as
Ledger. - Select an element in the list, such as Header Row or First Row Stripe, and click Format. You can set font, border, and fill.
- Tick Set as default table style for this document if you want new tables to use it.
Custom styles appear in a Custom group at the top of the gallery. They travel with the workbook. If you copy a table into another workbook, Excel copies the style definition too. To reuse the style in many workbooks, save one as a template (.xltx) and start new files from it.
To adjust a custom style later, right-click it in the gallery and choose Modify. Built-in styles cannot be modified, but you can right-click one and choose Duplicate, then edit the copy.
Stripe elements have a Stripe Size setting, for example 2 to shade pairs of rows. Banded Rows must be on for stripes to show.
Setting styles and options with VBA
The properties in the table above are on the ListObject. This macro applies a style and a set of options to a table named SalesTable:
Sub ApplyTableLook()
Dim tbl As ListObject
Set tbl = ActiveSheet.ListObjects("SalesTable")
tbl.TableStyle = "TableStyleMedium9"
tbl.ShowTableStyleRowStripes = True
tbl.ShowTableStyleColumnStripes = False
tbl.ShowTableStyleFirstColumn = True
tbl.ShowTableStyleLastColumn = False
tbl.ShowAutoFilterDropDown = True
End SubTo remove the style entirely, assign an empty string:
Sub ClearTableLook()
ActiveSheet.ListObjects("SalesTable").TableStyle = ""
End SubYou can list every style available in the workbook, built-in and custom, from the TableStyles collection. The Immediate window (Ctrl+G in the VBA editor) shows the output:
Sub ListTableStyles()
Dim ts As TableStyle
For Each ts In ActiveWorkbook.TableStyles
Debug.Print ts.Name
Next ts
End SubA custom style can be built in code as well. This macro defines a style named Ledger with a dark blue header and pale stripes, then applies it:
Sub CreateLedgerStyle()
Dim ts As TableStyle
On Error Resume Next
ActiveWorkbook.TableStyles("Ledger").Delete
On Error GoTo 0
Set ts = ActiveWorkbook.TableStyles.Add("Ledger")
With ts.TableStyleElements(xlHeaderRow)
.Interior.Color = RGB(31, 78, 121)
.Font.Color = RGB(255, 255, 255)
.Font.Bold = True
End With
With ts.TableStyleElements(xlRowStripe1)
.Interior.Color = RGB(221, 235, 247)
End With
ActiveSheet.ListObjects("SalesTable").TableStyle = "Ledger"
End SubThe On Error Resume Next block deletes an older copy first. TableStyles.Add raises an error if the name already exists.
Common problems
- Stripes disappear after you fill cells by hand. Direct fill overrides the style. Clear the fill from those cells.
- Style options are greyed out. The active cell is outside the table. Click inside it so the Table Design tab appears.
- Colors differ on another computer. The workbook theme or the Office version differs. Table colors follow the theme, so check Page Layout > Themes.
- Hidden header, but formulas still reference it. This is expected. The header names are intact. See
ShowHeaders. - A style looks fine on screen but prints poorly. Dark styles consume ink and may print as heavy blocks. Prefer a Light or Medium style for printed reports.
When you later convert the table back to a range, the style is flattened into ordinary cell formatting, so the look is kept. That conversion is covered in a later chapter.
Exercise
A colleague hands you a table where the stripes do not alternate in a block of rows, and the Banded Rows box is ticked. What is the most likely cause, and how do you fix it without removing the table?
Show answer
Someone applied direct fill formatting to those cells, and direct formatting overrides the table style. Select the affected cells and clear the fill (Home > Fill Color > No Fill), or select the table body and use Home > Clear > Clear Formats, then reapply number formats if needed. The table and its style stay intact.
Exercise
Write a VBA statement that makes the table named SalesTable on the active sheet use no style, and name one thing that still works afterward.
Show answer
ActiveSheet.ListObjects("SalesTable").TableStyle = "" removes the visible formatting. The table still expands automatically when you type below it, and structured references such as SalesTable[Amount] still work.