by Svetlana Cheusheva, updated on
This tutorial explains how you can alternate row colors in Excel to automatically highlight every other row or column in your worksheets. You will also learn how to apply Excel banded rows and columns and find a few smart formulas to alternate row shading based on a value change.
It is a common practice to add shading to alternate rows in an Excel worksheet to make it easier to read. While it is a relatively easy job to highlight rows of data manually in a small table, it could be an arduous task in larger ones. A better way is to have row or column colors alternated automatically and this article is going to show you how you can quickly do this.
When it comes to shading every other row in Excel, most gurus will immediately point you to conditional formatting, where you will have to invest some time in figuring out an ingenious mix of MOD and ROW functions.
If you'd rather not use a sledge-hammer to crack nuts, meaning you don't want to waste your time and creativity on such a trifle as zebra striping Excel tables, consider applying the built-in Excel table styles as a quick alternative.
The fastest and easiest way to apply row shading in Excel is by using predefined table styles. Along with other benefits of tables such as automatic filtering, color banding is applied to rows by default. All you need to do is convert a range of cells to table. For this, simply select your range of cells and press the Ctrl+T keys together.
Once you do this, the odd and even rows in your table will get shaded with different colors automatically. The best thing is that automatic banding will continue as you sort, delete or add new rows to your table.
If you'd rather have alternate row shading only, without the table functionality, you can easily convert the table back to a usual range. To do this, select any cell within your table, right click and choose Convert to Range from the context menu.
Note. After performing the table-to-range transformation, you won't get the automatic color banding for newly added rows. Another disadvantage is that if you sort the data, your color bands will travel with the original rows and your nice zebra stripe pattern will get distorted.
As you can see, converting a range to table is a very easy and quick way of highlighting alternate rows in Excel. But what if you want a bit more?
If you are not happy with the default blue and white pattern of an Excel table, you have plenty more patterns and colors to choose from. Just select your table or any cell within the table, switch to the Design tab > Table Styles group and select the colors of your liking.
You can use the arrow buttons to scroll through the available table styles or click the More button to view them all. When you hover the mouse cursor over any style, it is immediately reflected to your table and you can see how your banded rows would look like.
In case you want to highlight a different number of rows in each stripe, e.g. shade 2 rows in one color and 3 in another, then you will need to create a custom table style. Assuming that you have already converted a range to table, perform the following steps:
Note: Custom table styles are stored only in the current workbook and therefore are not available in your other workbooks. To use your custom table style as the default table style in the current workbook, select the "Set as default table style for this document" check box when creating or modifying the style.
If you are not happy with the style you created, you can easily modify it by right-clicking your custom style in the Styles Gallery and choosing Modify from the context menu. And here you have plenty of room for your creativity! You can set any Font, Border, and Fill styles on the corresponding tabs, even choose gradient stripe colors, as you see in the screenshot below : )
If you no longer want to have color banding in your Excel table, you can remove them literally in a single click. Select any cell in your table, go to the Design tab and uncheck the Banded rows option.
As you see, Excel's predefined table styles provide a wealth of features to alternate color rows in your worksheets and create custom banded rows styles. I believe they will suffice in many situations, though if you want something special, e.g. shading entire rows based on a change of value, then you will need to use conditional formatting.
It goes without saying that conditional formatting is a bit trickier that Excel table styles we have just discussed. But it has one undisputable benefit - it allows more room for your imagination and lets you zebra stripe your worksheet exactly as you want it is each particular case. Further on in this article, you will find a few examples of Excel formulas for alternating row colors:
We are going to start with a very simple MOD formula that highlights every other row in Excel. In fact, you can achieve exactly the same result using Excel Table styles, but the main benefit of conditional formatting is that it works for ranges as well, meaning that your color banding will remain intact as you sort, insert or delete rows in a range of data to which your formula applies.
You create a conditional formatting rule in this way:
=MOD(ROW(),2)=0
At this point, the selected color will appear under Sample. If you are happy with the color, click OK.
And here's how the result looks like in my Excel 2013:
If you'd rather have 2 different colors instead of white lines, then create a second rule using this formula:
=MOD(ROW(),2)=1
And now you have odd and even rows highlighted with different colours:
That was pretty easy, wasn't it? And now I'd like to briefly explain the syntax of the MOD function because we are going to use it in other a bit more complex examples.
The MOD function returns the remainder rounded to the nearest integer after the number is divided by the divisor.
For example, =MOD(4,2)
returns 0, because 4 is divided by 2 evenly (without remainder).
Now, let's see what exactly our MOD function, one that we've used in the above example, does. As you remember we used a combination of the MOD and ROW functions: =MOD(ROW(),2)
The syntax is simple and straightforward: the ROW function returns the row number, then the MOD function divides it by 2 and returns the remainder rounded to the integer. When applied to our table, the formula returns the following results:
Row No. | Formula | Result |
---|---|---|
Row 2 | =MOD(2,2) | 0 |
Row 3 | =MOD(3,2) | 1 |
Row 4 | =MOD(4,2) | 0 |
Row 5 | =MOD(5,2) | 1 |
Do you see the pattern? It's always 0 for even rows and 1 for odd rows. And then we create the conditional formatting rules telling Excel to shade odd rows (where the MOD function returns 1) in one color and even rows (that have 0) in another color.
Now that you know the basics, let's look into more sophisticated examples.
You can use the following formulas to shade a fixed number of rows, regardless of their content:
Odd row shading, i.e. highlight the 1st group and every other group:
=MOD(ROW()-RowNum,N*2)+1<=N
Even row shading, i.e. highlight the 2nd group and all even groups:
=MOD(ROW()-RowNum,N*2)>=N
Where RowNum is a reference to your first cell with data and N is the number of rows in each banded group.
Tip: If you want to highlight both even and odd groups, then simply create 2 conditional formatting rules with both of the above formulas.
You can find a few examples of formula usage and the resulting color banding in the following table.
To color every 2 rows, starting from the 1st group. The data starts in row 2. | =MOD(ROW()-2,4)+1<=2 |
![]() |
---|---|---|
To color every 2 rows, starting from the 2nd group. The data starts in row 2. | =MOD(ROW()-2,4)>=2 |
![]() |
To color every 3 rows, starting from the 2nd group. The data starts in row 3. | =MOD(ROW()-3,6)>=3 |
![]() |
If you think your data will look better with rows shaded in three different colors, then create 3 conditional formatting rules with these formulas:
To highlight 1st and every 3rd row =MOD(ROW($A2)+3-1,3)=1
To highlight 2nd, 6th, 9th etc. =MOD(ROW($A2)+3-1,3)=2
To highlight 3rd, 7th, 10th etc. =MOD(ROW($A2)+3-1,3)=0
Remember to replace A2 with a reference to your first cell with data.
The resulting table will look similar to this in your Excel:
This task is similar to the one we discussed a moment ago - shading groups of rows, with the difference that there may be a different number of rows in each group. I believe, this will be easier to understand from an example.
Suppose, you have a table containing data from different sources, e.g. regional sales reports. What you want is shade the first group of rows related to the first product in Color 1, the next group related to the second product in Color 2 and so on. Column A listing the product names may serve as the key column or unique identifier.
To alternate row shading based on change of value, you'd need a bit more complex formula and an additional column:
=MOD(IF(ROW()=2,0,IF(A2=A1,F1, F1+1)), 2)
The formula will fill down column F with blocks of 0 and 1, every new block staring with the Product name change.
=$F2=1
. You can add a second rule =$F2=0
if you want a second color to alternate blocks of rows, as shown in the screenshot:
In fact, shading columns in Excel is pretty much similar to alternating rows. If you have understood all of the above, this part is going to be a piece of pie for you : )
You can apply shading to columns in Excel by using either:
In case you'd like prettier colors, you are free to choose any other pattern from the Table Styles Gallery.
If you want to shade a different number of columns in each stripe, then create a duplicate of an existing table style of your choosing, exactly as described here. The only difference is that you choose "First Colum Stripe" and "Second Colum Stripe" instead of the corresponding row stripes.
And this is how your custom column bands may look like in Excel:
The formulas to apply color banding to alternate columns in Excel are very similar to the ones we've used for shading alternate rows. You just need to use the MOD function in conjunction with the COLUMN function rather than ROW. I will name but a few in the table below and I'm sure you will easily convert other "row formulas" to "column formulas" by analogy.
To color every other column | =MOD(COLUMN(),2)=0 and/or =MOD(COLUMN(),2)=1 |
![]() |
---|---|---|
To color every 2 columns, starting from the 1st group | =MOD(COLUMN()-1,4)+1<=2 |
![]() |
To shade columns with 3 different colors | =MOD(COLUMN()+3,3)=1 =MOD(COLUMN()+3,3)=2 =MOD(COLUMN()+3,3)=0 |
![]() |
Hopefully, now you won't have any problems with applying color banding in Excel to make your worksheets handsome and more readable. If you want to alternate row or column colors in some other way, don't hesitate to leave me a comment and we will figure this out together. Thank you for reading!
Table of contents