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

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 (2889) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: **Patterns of Numbers with a Formula**.

**Program Successfully in Excel!** John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out *Excel 2013 Power Programming with VBA* today!

When you subtract two numbers from each other, you have a certain expectation of what Excel should deliver. What if you ...

Discover MoreWant to sum the values in the same cell on a range of worksheets? It's not as easy as summing a range on the same ...

Discover MoreGiven a range of cells, you may at some time want to calculate the sum of only the largest values in that range. Here is ...

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

2019-02-01 11:56:53

Ricardo

2015-01-05 10:43:19

Fernando Romero H.

Excelent page, very helpfully i used to create great reports, thanks.

Got a version of Excel that uses the
menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)?
**This site is for you!** If you
use a later version of Excel, visit
our *ExcelTips* site focusing on the ribbon interface.

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

Copyright © 2019 Sharon Parq Associates, Inc.

## Comments