Cycle Through a List with MOD

Excel Formulas › Math

All versionsMOD

Need to repeat a sequence — assign shifts in rotation, alternate colors, cycle through a roster? MOD wraps a counter back to the start so an index loops 1, 2, 3, 1, 2, 3… forever.


Quick formula: cycle a row number through a list of length N:
=MOD(ROW()-2, N) + 1
MOD gives the remainder, so the counter resets every N rows; +1 shifts it to a 1-based position.

Functions used (tap for the full reference guide):

The example

Rotate through 3 names endlessly.

AB
1RowSlot (of 3)
211
341
452

The formula

The formula:

=MOD(ROW()-2, N) + 1 // wraps every N

How it works

How it works:

  1. MOD(counter, N) returns the remainder, which cycles 0, 1, …, N−1, then resets.
  2. Add 1 to get a 1-based slot (1…N) for use with INDEX.
  3. Pair with INDEX to pull the actual item: =INDEX(list, MOD(ROW()-2, N)+1).
  4. Use it for round-robin assignment, alternating bands, repeating schedules, or zebra-striping by group.

Alternating two states is the simplest case: =MOD(ROW(), 2) returns 0, 1, 0, 1… — perfect for even/odd logic or two-color banding. For three or more, raise the divisor to match the cycle length.

Try it: interactive demo

Live demo

Cycle length and position.

Slot

Variations

Pull the item

With INDEX:

=INDEX(list, MOD(ROW()-2, N)+1)

Alternate two

Even/odd:

=MOD(ROW(), 2)

Group of N rows

Block number:

=INT((ROW()-2)/N) + 1

Pitfalls & errors

Mind the offset. Subtract the header rows so the first data row starts the cycle at the right slot.

+1 for 1-based. MOD is zero-based; add 1 before feeding INDEX.

N must be positive. A zero or negative divisor errors or gives odd results.

Practice workbook

📊
Download the free Cycle Through a List with MOD practice workbook
A MOD-cycling sheet with the INDEX, alternate-two, and group-block variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I cycle through a list repeatedly in Excel?
Use =MOD(counter-1, N)+1 to loop an index 1..N..1, then feed it to INDEX: =INDEX(list, MOD(ROW()-2, N)+1).
How do I alternate between two values per row?
Use =MOD(ROW(), 2), which returns 0,1,0,1… — pair with IF or use it for two-color banding.
How do I assign items in round-robin?
Cycle the index with MOD so each row gets the next person in rotation, wrapping back to the first after N.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: MOD function · INDEX & MATCH · Sequence of numbers

Function references: MOD · INDEX