Excel guide · 5 min read
How to shade alternate rows in Excel
=MOD(ROW(),2)=0. Avoid coloring rows by hand: the fills move with the data when you sort.Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Region | Rep | Orders | Revenue |
| 2 | East | Hannah Cole | 42 | 18900 |
| 3 | East | Marcus Webb | 37 | 16240 |
| 4 | East | Priya Nair | 51 | 22410 |
| 5 | North | Daniel Ortiz | 29 | 12780 |
| 6 | North | Grace Kim | 33 | 14150 |
| 7 | South | Liam Foster | 46 | 20330 |
| 8 | West | Olivia Brooks | 39 | 17020 |
| 9 | West | Ethan Shaw | 44 | 19260 |
| 10 | West | Chloe Martin | 31 | 13490 |
Download this sheet as an Excel practice file (.xlsx)
Method 1: Format as Table (the easy, sturdy way)
You have a list of nine sales reps and their revenue, and your manager wants it easier to read across. Banded rows help the eye follow a row from the name to the number.
A table bands the rows for you, and the banding is tied to position, not to the data. Sort by Revenue, filter to one region, or add a rep at the bottom, and the stripes stay alternating.
- Click any cell in the data.
- Press Ctrl+T (or Home > Format as Table and pick a style).
- Check that "My table has headers" is ticked, then click OK.
- To change the look, go to Table Design and pick another style. The Banded Rows box on the same tab turns the stripes on or off; Banded Columns stripes the columns instead.
Method 2: A conditional formatting rule with MOD and ROW
If you don't want a table (shared templates, merged headers, or a sheet that feeds other formulas), use a rule. ROW() returns the row number, and MOD(ROW(),2) is 0 on even rows and 1 on odd rows. So =MOD(ROW(),2)=0 is TRUE on rows 2, 4, 6 and so on.
Here it's shown with a fixed reference so you can see the test: Hannah's row 2 is even, so the rule is TRUE and that row gets the fill. Row 3 returns FALSE and stays white. Use =MOD(ROW(),2)=1 instead to shade the odd rows.
Because the rule looks at the row number, the stripes stay perfect after sorting. Hand-colored rows don't: the fill moves with each rep, and your neat stripes turn into a random pattern.
- Select the data rows, A2:D10 (leave the header out if it has its own style).
- Home > Conditional Formatting > New Rule.
- Choose "Use a formula to determine which cells to format".
- Enter
=MOD(ROW(),2)=0, click Format, pick a light fill on the Fill tab, and click OK twice.
Result: TRUE
TRUE: row 2 is even, so it's shaded. Row 3 gives FALSE.
Keep the stripes right after filtering
The MOD(ROW()) rule has one weakness. Filter the list to East and West, and the hidden rows break the pattern: two shaded rows can end up next to each other. A table re-stripes visible rows, but a rule needs a different test.
SUBTOTAL(103,range) counts only the visible non-empty cells. =SUBTOTAL(103,$A$2:$A2) counts the visible rows from the top down to the current one, so shading when that count is even always alternates on screen. The $A$2 start is locked and the end $A2 grows as the rule moves down.
With nothing filtered, row 5 is the 4th visible row, so it's shaded. Filter out some rows and the count changes to match what you see.
Result: TRUE
TRUE: 4 visible rows from A2 to A5, an even count, so row 5 is shaded.
Band by group: shade each region in turn
Sometimes you want the stripes to follow a value instead: all East rows white, all North rows gray, South white again. That makes groups pop on a sorted list.
Count how many times the region has changed from the top down to the current row. $A$2:$A5<>$A$1:$A4 compares each region with the one above it; the header in A1 counts as a change, so East starts the count at 1. Shade when the count is even. At row 5 the count is 2 (East, then North), so the North rows are shaded. South makes it 3 and West 4.
The data must be sorted by the group column first. Use the rule =MOD(SUMPRODUCT(--($A$2:$A2<>$A$1:$A1)),2)=0 on A2:D10.
Result: TRUE
TRUE: North is the 2nd region from the top, so its rows are shaded.
Every third row, or bands of three
For long lists people sometimes prefer a line every few rows. Subtract the first data row so the counting starts at 0: =MOD(ROW()-ROW($A$2),3)=0 shades rows 2, 5 and 8, the start of each block of three. Row 5 returns TRUE.
For thick bands (three white rows, three shaded rows), divide first: =MOD(INT((ROW()-2)/3),2)=0 is TRUE for rows 2-4 and FALSE for rows 5-7. Change the 3 to any band size.
If a rule doesn't seem to do anything, check that you entered it with the first selected row in mind, and that a table style or manual fill isn't covering it. Cellwise Fix (cellwise.app/excel-formula-helper/) can check a rule formula against your own rows.
Result: TRUE
TRUE: row 5 is the start of the second block of three.
Common mistakes
Coloring every other row by hand
Manual fills move with the data when you sort. Use a table or a MOD(ROW()) rule, which are tied to the row position.
Stripes break after filtering
MOD(ROW()) counts hidden rows. Use a table, or the rule =MOD(SUBTOTAL(103,$A$2:$A2),2)=0.
Table banding and a rule fighting
Conditional formatting draws on top of the table style, so you may see odd colors. Pick one: turn off Banded Rows on Table Design, or delete the rule in Conditional Formatting > Manage Rules.
Converting the table to a range and sorting
After Table Design > Convert to Range the stripes become ordinary fills and scramble on the next sort. Add a MOD(ROW()) rule if you need a plain range.
FAQ
How do I shade every other row in Excel without a table?
Select the rows, go to Home > Conditional Formatting > New Rule > "Use a formula", and enter =MOD(ROW(),2)=0. Pick a fill and click OK.
How do I alternate row colors in Google Sheets?
Google Sheets has Format > Alternating colors, which works like Excel's table banding. The same =MOD(ROW(),2)=0 rule also works there as a custom formula in conditional formatting.
Can I use ISEVEN(ROW()) instead of MOD?
In Excel, yes: =ISEVEN(ROW()) gives the same stripes as =MOD(ROW(),2)=0. MOD is shown here because it also handles every 3rd row and other band sizes.
How do I shade alternate columns?
Use COLUMN instead of ROW: =MOD(COLUMN(),2)=0. In a table, tick Banded Columns on the Table Design tab.
Functions used
MODRemainder after divisionROWRow number of a cellSUBTOTALTotal that skips other subtotalsSUMPRODUCTMultiply then addINTRounds down to integerCOLUMNColumn number of a cell
Related guides
- Highlight an entire row based on one cell's value
- Conditional formatting formula not working: how to fix it
- How to highlight weekends in Excel
- Sum every other row (or every nth row) in Excel
- How to use a custom formula in Excel Data Validation
- How to count by hour in Excel
Updated