Earn your certification as a Financial Modeling & Valuation Analyst (FMVA)®. Register today!

ROW Function

Returns the first row within a given reference or the number of the current row

How to Alternate Row Color in Excel?

To alternate row color in excel, you can do so by applying conditional formatting, with a combination of functions. The ROW function is a TEXT function, that will return the first row within a given reference or the number of the current row. If you combine the ROW with the ISODD/ISEVEN and the CEILING function, you can easily alternate the row color of a selected range of cells. 

Depending on your purpose for alternating row colors, there is a simple way to do it. If you select the range that you desire and then insert a table, this should automatically alternate the row colors, there are multiple table styles that you can select from to fit the style guide that you are looking for. This guide is for a little more complicated, but with a greater room for customization option.

In financial analysis, alternating row color can improve the readability of your spreadsheet. It also facilitates grouping information, such as highlighting alternating groups of n rows.

Step-by-Step Guide

Suppose that we have a table of values in excel such as the one below. If we want to alternate our row color for every n rows, – i.e 3 rows grey, 3 rows no fill – you should select the range of rows that you want to apply the alternating rows. Then you should select 

 

ROW Function

 

The formula to use would be =ISEVEN(CEILING(ROW()-4,3/3).

 

ROW Function - Example 1

 

We will get the results below:

 

ROW Function - Example 1a

 

In the formula above, we first “normalize” the row numbers to begin with 1 using the ROW function and an offset.

Here, we used an offset of 4. The result goes into the CEILING function, which rounds incoming values up to a given multiple of n. Essentially, the CEILING function counts by a given multiple of n.

The count is then divided by n to count by groups of n, starting with 1. Finally, the ISEVEN function is used to force a TRUE result for all even row groups, which triggers the conditional formatting.

Odd row groups return FALSE, so no conditional formatting is applied.

We can replace ISEVEN with ISODD to shade rows starting with the first group of n rows, instead of the second.

Click here to download the sample Excel file

The ROW() Function

=ROW(reference)

The ROW function uses Reference as an argument. The reference is supposed to be a cell, that the function will retrieve the row value.

If you instead leave the argument blank and simply enter =ROW(), the function will return the row of where the function is. So, for example, let’s assume you enter the function =ROW() on cell D22, the function will return 22. If instead, you enter the function =ROW(C7), the function will return the 7.

A reference can not refer to multiple areas.

Additional resources

Feel free to contact CFI if you have any further questions on how to use the row function and otherBy taking the time to learn and master these functions, you’ll significantly speed up your financial modeling. To learn more, check out these additional resources:

  • Excel Functions for Finance
  • Advanced Excel Formulas Course
  • Excel Shortcuts for PC and Mac
  • Get Your Financial Modeling Certification

Free Excel Tutorial

To master the art of Excel, check out CFI’s FREE Excel Crash Course, which teaches you how to become an Excel power user.  Learn the most important formulas, functions, and shortcuts to become confident in your financial analysis.

 

Launch CFI’s Free Excel Course now to take your career to the next level and move up the ladder!