To use MOD to flag every nth row in Excel, add a helper column with one short formula and copy it down your data. Rows that match your interval show TRUE, while all other rows show FALSE. It works well for picking every 3rd order for a quality check or every 10th record for a review.
Key Takeaways
- Use =MOD(ROW()-ROW($A$1),3)=0 to flag every 3rd data row when the header is in row 1.
- Change the 3 to any whole number to set a different interval.
- TRUE marks a flagged row, and FALSE marks a row to skip.
- Point the header reference at your own header cell so the count starts in the right place.
- The same formula can highlight the flagged rows through Conditional Formatting.
How to Use MOD to Flag Every Nth Row in Excel
The example here has headers in row 1, data in columns A through D starting in row 2, and an empty column E for the flags. The goal is to mark every 3rd data row.
Add the Flag Formula
- Step 1: Open the worksheet and click cell E1. Type Flag as the column header, then press Enter.
- Step 2: In cell E2, type =MOD(ROW()-ROW($A$1),3)=0 into the cell.
- Step 3: Press Enter. Cell E2 shows FALSE because it holds the first data row.
- Step 4: Select E2 again and double-click the fill handle, the small square at the bottom-right corner of the cell. Excel copies the formula down alongside your data.
- Step 5: Check the results. TRUE should appear in rows 4, 7, 10 and so on, which are the 3rd, 6th and 9th data rows.

Think of MOD as a counter that resets after every third beat. ROW()-ROW($A$1) gives each data row a position number, and MOD returns the remainder after dividing that number by 3. A remainder of 0 means the row lands exactly on the interval.
Tip: If your header sits in a different row, replace $A$1 with that header cell. For a header in row 5, use $A$5 and enter the first formula in row 6. Keep the dollar signs so the reference stays locked while copying.
Change the Interval or Starting Row
- Step 1: To change the interval, replace the 3 in E2. For example, =MOD(ROW()-ROW($A$1),5)=0 flags every 5th data row.
- Step 2: To flag the 1st, 4th and 7th data rows instead, use =MOD(ROW()-ROW($A$1)-1,3)=0 in E2.
- Step 3: Copy the updated formula down the column again so every row follows the new pattern.
Most people find it easier to keep the interval in its own cell. Type the number in G1, enter =MOD(ROW()-ROW($A$1),$G$1)=0 in E2, and fill it down. After that, editing G1 updates every flag.
Highlight the Flagged Rows
This works best when the flagged rows need to stand out at a glance.
- Step 1: Select the data range without the header, such as A2:D100, starting the selection from cell A2.
- Step 2: On the Home tab, click Conditional Formatting, then click New Rule.
- Step 3: Choose Use a formula to determine which cells to format.
- Step 4: In the formula box, enter =MOD(ROW()-ROW($A$1),3)=0.
- Step 5: Click Format, open the Fill tab, pick a color, and click OK.
- Step 6: Click OK again to apply the rule.

Tip: To keep the highlight tied to the interval cell, use =MOD(ROW()-ROW($A$1),$G$1)=0 as the rule. A new number in G1 then shifts the colored rows right away.
Common Problems and Fixes
The Wrong Rows Are Flagged
The header reference is usually the cause. Make sure it points to the cell in the row directly above the first data row. With data starting in row 2, that reference is $A$1.
The #DIV/0! Error Appears
The divisor is zero or the interval cell is empty. Enter a whole number of 1 or higher in G1, or type the number directly into the formula.
The #VALUE! Error Appears
The interval cell contains text that Excel cannot read as a number, such as the word three. Replace it with the digit 3.
The Formula Shows as Text
The cell is likely formatted as Text. Select the column, set the number format to General on the Home tab, re-enter the formula in E2, and fill it down again. Also confirm that the entry begins with an equal sign.
Copied Formulas Do Not Update
Workbook calculation may be set to manual. Go to the Formulas tab, click Calculation Options, and select Automatic.
The Highlight Is Off by One or More Rows
Open Conditional Formatting, click Manage Rules, and check both the formula and the Applies to range. The range should begin at the first data row, and the formula should reference the header cell above it.
Frequently Asked Questions
What formula flags every nth row in Excel?
With a header in row 1, enter =MOD(ROW()-ROW($A$1),n)=0 in row 2, replace n with your interval, and copy the formula down.
How do I flag every other row with MOD?
Use =MOD(ROW()-ROW($A$1),2)=0. It returns TRUE for the 2nd, 4th, 6th and later even-numbered data rows.
How do I start flagging from the first data row?
Use =MOD(ROW()-ROW($A$1)-1,n)=0 and replace n with your interval. The first data row is flagged, followed by every nth row after it.
Can the flag show 1 and 0 instead of TRUE and FALSE?
Yes. Use =–(MOD(ROW()-ROW($A$1),3)=0). The two minus signs convert TRUE to 1 and FALSE to 0.
Does the formula work if there is no header row?
Yes. If the data starts in row 1, use =MOD(ROW(),3)=0 in the first row of the helper column and copy it down.
What happens to the flags after inserting or deleting rows?
The flags recalculate based on the new row positions. Copy the formula into any newly inserted rows if Excel does not fill it automatically.
Does MOD with ROW skip hidden or filtered rows?
No. ROW returns the actual worksheet row number, so hidden and filtered rows are still included in the count.
Why does Excel reject the commas in the formula?
Some regional settings use a semicolon as the argument separator. In that case, enter the formula as =MOD(ROW()-ROW($A$1);3)=0.