How-to recipes · Formatting

How to shade alternate rows in Excel

Add zebra stripes to a list with a table style or a MOD(ROW()) conditional formatting rule, keep them after filtering, and band groups of rows.

Beginner MOD ROW ISEVEN SUBTOTAL SUMPRODUCT

Banded rows, also called zebra stripes, make wide lists much easier to read: your eye can follow a row across ten columns without jumping to the line above. Colouring every second row by hand is tedious and breaks as soon as you sort, insert or delete a row. Excel can do it automatically in two ways: with an Excel table style, or with a conditional formatting formula that you control completely.

Method 1: format as a table (quickest)

  1. Click anywhere in the list.
  2. Press Ctrl+T (Insert > Table), confirm the range and that the list has headers.
  3. Choose a style from Table Design > Table Styles. Make sure Banded Rows is ticked in Table Style Options.

The stripes adjust automatically when you sort, filter, add or delete rows, and you also get filter buttons, structured references and an expanding range. This is the recommended method for most lists; see Excel tables and structured references. If you want the stripes but not the table, convert it back with Table Design > Convert to Range: the formatting stays, but it becomes static and no longer adjusts (How to convert a table to a normal range in Excel).

Method 2: conditional formatting with MOD(ROW())

A formula rule gives the same stripes on any range without turning it into a table. The test is whether the row number is even. Check it in a cell first:

C4fx=MOD(ROW(),2)=0
ABC
1ProductQtyEven row?
2Cable120
3Charger45
4Mouse310TRUE
5Keyboard140
6Headset60

Row 4 is even: 4 divided by 2 leaves remainder 0, so the test is TRUE.

Result: TRUE

  1. Select the data range, for example A2:F200.
  2. Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format.
  3. Enter =MOD(ROW(),2)=0.
  4. Click Format > Fill, choose a light grey or pale blue, and click OK twice.

ROW returns the row number of each cell and MOD the remainder after dividing by 2. Use =MOD(ROW(),2)=1 to stripe the odd rows instead, or =ISEVEN(ROW()) with ISEVEN, which reads more naturally. Because the rule is evaluated live, sorting and inserting rows never breaks the pattern.

Wider bands

To shade blocks of three rows (three white, three grey), divide the row number first: =MOD(INT((ROW()-2)/3),2)=1. Change 3 to any block size; the -2 aligns the bands with the first data row.

Stripes that survive filtering

With MOD(ROW()), filtering hides some rows, and the visible rows may end up with two grey rows next to each other. Count only the visible rows with SUBTOTAL instead of using the row number:

Formula
=MOD(SUBTOTAL(103,$A$2:$A2),2)=0

SUBTOTAL(103,$A$2:$A2) counts the visible non-empty cells from the first data row down to the current one. The count only increases on visible rows, so the stripes alternate correctly however you filter. Column A must not contain blanks for this to work. Tables do this automatically.

Banding by group

For lists where several rows belong together, such as order lines, shading each order in alternating colours is more useful than shading single rows. Add a helper column that counts distinct orders so far, or use a rule like:

C5fx=MOD(SUMPRODUCT(1/COUNTIF($A$2:$A5,$A$2:$A5)),2)
ABC
1OrderLineGroup band
2SO-11
3SO-12
4SO-21
5SO-311
6SO-32
7SO-33

Up to row 5 there are three distinct orders (SO-1, SO-2, SO-3), so the band value is 1: SO-3 gets the shaded colour.

Result: 1

As a rule formula, =MOD(SUMPRODUCT(1/COUNTIF($A$2:$A2,$A$2:$A2)),2)=1 shades orders 1, 3, 5 ... The data must be sorted by order. On long lists this is slow; a helper column is faster: type 0 in C2 and =IF(A3=A2,C2,1-C2) in C3, copied down, which toggles between 0 and 1 whenever the order changes.

Pitfalls

  • Rule and manual fills. Conditional formatting sits on top of manual fill colours; remove old manual fills first or the result looks patchy.
  • Mixed methods. Applying a MOD rule to a table that already has banded rows gives a confusing pattern. Pick one method.
  • Printing. Very light colours may disappear on some printers; check with File > Print preview.
  • Accessibility. Keep the contrast between text and the band colour high, and do not rely on stripes to convey meaning.
Tip. Other formula-based formats are collected in How to use conditional formatting with a formula in Excel. Basic cell formatting is covered in Formatting cells: fonts, alignment, borders and styles.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 14 KB

More how-to recipes