 Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Patterns of Numbers with a Formula.

# Patterns of Numbers with a Formula by Allen Wyatt
(last updated December 1, 2021)

Helen has used a macro to generate a simple pattern of numbers. The pattern, which is contained in a single column, looks like this:

```1,1,0,2,2,0,3,3,0,4,4,0,...
```

Helen was wondering if there is a way to generate the same pattern using a formula instead of a macro.

Actually, there are several different formulas you can use to achieve the desired pattern. One way is to start with your seed sequence (1, 1, 0) in cells A1 through A3. Then, enter the formula =A1+1 into cell A4, the formula =A4 into cell A5, and the formula =A3 into cell A6. Now you can select the cells in A4:A6 and use the fill handle to drag and fill however many rows you need.

A different formulaic approach is to still put your seed sequence (1, 1, 0) in cells A1 through A3, and then enter the following formula into cell A4:

```=IF(A1<>0,A1+1,0)
```

You can copy this formula down as many cells as necessary to repeat the desired pattern.

If you don't want to use a seed sequence (for instance, the sequence will always start with 1, 1, 0), then can use a straight formula starting with cell A1. Either of the following formulas will produce the same results:

```=IF(MOD(ROW(),3)=0,0,INT(ROW()/3)+1)
=(INT(ROW()/3)+1)*(MOD(ROW(),3)<>0)
```

The formulas (and many variations of these formulas) examine the row in which the formula is positioned, and then figure out whether it is in the first, second, or third row of each set. Based on this position, the formula figures out whether it should show the "set number" (1, 2, 3, etc.) or a zero value.

If your pattern doesn't start in the first row of a worksheet, you need to adjust the formula to account for an offset from the first row. For instance, if the pattern is going to start in the second row (you may have a header in the first row), then the formulas can be adjusted in this manner:

```=IF(MOD(ROW()-1,3)=0,0,INT((ROW()-1)/3)+1)
=(INT((ROW()-1)/3)+1)*(MOD(ROW()-1,3)<>0)
```

Simply put the formula into the second row and copy it down, as required. To adjust the offset for any other row, just change the -1 values (two of them in each formula) to the number of rows you have pushed down the formula from the first row.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (11988) applies to Microsoft Excel 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Excel here: Patterns of Numbers with a Formula.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

External Data Validation

When using data validation, you may want to reference a list of validation criteria contained on a different worksheet. ...

Discover More

Hiding Fonts

Windows makes it easy to manage the fonts installed on your system. One of the lesser-known options is one that allows ...

Discover More

If you receive a document from somebody else, you might not be able to edit it if the document contains fonts that you ...

Discover More Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

##### More ExcelTips (ribbon)

Returning Zero When a Referenced Cell is Blank

Reference a cell in a macro, and if that cell is blank Excel normally equates that to a zero value. What if you don't ...

Discover More

Developing Reciprocal Conversion Formulas

When converting between measurement systems, you might want to use two cells for each type of measurement. Make a change ...

Discover More

Retrieving the Last Value in a Column

Need to get at the last value in a column, regardless of how many cells are used within that column? You can apply the ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine more than 9?

2021-12-30 10:18:31

Ferreira

Very good, very, very

2016-07-09 22:59:01

allen@sharonparq.com

Robert: The MOD function gives the remainder after the division. 3 divides into 6 evenly -- 2 times (6/3 = 2). So there is 0 left over, which is why MOD returns 0.

Try 6 MOD 4, though: 4 only goes into 6 once, and the remainder would be 2 (the remainder is what is left over after the integer division).

-Allen

2016-07-09 22:35:02

Robert

I have a question: if the following division 6/3 gives a remainder of 2, how is it that when I use the same division with the MOD function, it gives me a remainder of 0. Maybe I am missing something in the way MOD works. Thank you.

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.