What’s New About Sequence
Of course, Excel has long afforded us the means for unrolling a sequence of values across, or down, a spreadsheet. If you needed to enter a skein of numbers 1 through 100, we’d just enter the 1 and the 2 – thus establishing the desired interval, or step, of 1 – grab onto the AutoFill button, and pull it down 98 more rows, or across for as many columns. Moreover, if you had already entered a list of 100 names, you could post the 1 and 2 in the adjoining left column, select that tandem of values, and double-click the AutoFill button. Presto – 3 through 100 would appear.
=SEQUENCE(no. of rows,no. of columns,first value,step)
=SEQUENCE(30,1,1,1)
will elaborate a sequence 30 rows high, one column wide, begin the sequence with the value 1, and step, or increment, each succeeding value by 1. In other words, write the above formula and you wind up with numbers 1 through 30 diving down a column.
=SEQUENCE(30)
=SEQUENCE(,30)
will sequence the 1–30 values across a column. But here you do need to enter that initial comma, in order to alert the formula that the 30 has leapfrogged the row argument and bounded into the column reference.
=SEQUENCE(30,,6,2)
30 rows’ (and one column’s) worth of values starting with 6 and stepping up in increments of 2 will result, for example, in 6,8,10,12, etc.
=SEQUENCE(10,3,,4)
Note, by the way, that here the sequence spills across its rows, and not down.
=SEQUENCE(12,,,0)
The 0 step means just that; nothing is added to the next sequenced value. Start with 1 and end up with 1 – 12 times.
And let’s remind ourselves that all of these sequences radiate from a single formula. Remember – we’re in dynamic array territory.
The Possibilities Proliferate
Now that you’re getting the hang of SEQUENCE you can begin to think of all sorts of ways in which the function can do your bidding, sometimes in conjunction with other functions, and with some judicious formatting.
=SEQUENCE(COUNTA(B2:B1000))
=SEQUENCE(4)
Simple but useful indeed, though a couple of cautions need be sounded. For one, don’t try to assign IDs to names via this technique, because if you sort the names, the numbers won’t follow along with them. The SEQUENCE formula merely counts the names, but has no interest in which name currently finds itself alongside any spilled value. And secondly, remember – you can’t write the above formula to a table.
Though we observed earlier that you can’t normally delete a spilled value (as opposed to the actual formula), you can here delete a row containing one of the values, and the SEQUENCE will recalibrate accordingly. Thus, if you delete the row containing the sequenced value 3, the row beneath will acquire the 3, etc.
Spates of Dates
=SEQUENCE(5,7,TODAY(),1)
=SEQUENCE(5,7,44664,1)
And treat the spill to the appropriate date format.
=SEQUENCE(365,,44562)
44562 signifies January 1, 2022, and so our formula will sequence all the days of 2022 down one column – and enable you to enter notes associated with each date in the column to its immediate right. Remember that the omitted arguments here – the column count and the step number – default to 1.
=SEQUENCE(13,,6/24,1/24)
To break down the formula: the 13 attests to the number of rows required by the sequence – 13, because the first row returns 6:00 a.m., and we need 12 more to mark out the intervals for all 12 hours.
PMT, Again: The Sequel, with Sequence
=SEQUENCE(,5,0.02,0.01)
Five columns, a start number of .02 (2%, of course, in the desired formatting), and an interval of .01.
=SEQUENCE(6,,12,12)
=PMT(G7#/12,F8#,G4)
(And note the pound-sign references in the formula.)
=SEQUENCE(,G1,0.02,0.01)
which would enable you to enter any value in G1 without having to edit the formula. The G1 entry would record as many interest intervals as you require.
And of course, you can do much the same for the payment frequencies, by substituting a new value for the 6 in its SEQUENCE. Thus we see that by working dynamically, new scenarios can suggest themselves in a flash.
The One-Formula Multiplication Table
Now let’s move from time to times. Suppose we want to construct a multiplication table – not of the old-school kind (literally), but rather a dynamic table, one that can grab any two ranges of values and flash all their multiplied products immediately. SEQUENCE can do the job – and with a grand total of one formula.
Start with a blank worksheet and enter the numbers 5 in B6 and 10 in C6. Those entries will impart, on our first go-round, the values 1 through 5 down a column and 1 through 10 across a set of columns, helping to form the outline of a matrix that will multiply every value by every other one.
=SEQUENCE(B6)*SEQUENCE(,C6)
Cool, if I do say so myself. Now enter different values in B6 and C6, and the table changes to reflect the new inputs, with the number of columns and rows expanding and contracting accordingly. It’s dynamic.
In fact, this formula takes us back to a lesson we’ve already learned, that is, our discussion in Chapter 3 of how perpendicular ranges behave toward one another. There we noted that if we multiply two such ranges, each value in the first range is multiplied by every value in the second – and that’s exactly what’s happening here. The first SEQUENCE formula dispatches its values down a column, and the second pushes its values across, at a right angle to the first. The difference here is that the two SEQUENCE formulas haven’t scooped up their values from ranges in the worksheet, as they did in Chapter 3; the 1-5 and 1-10 sequences have been assembled inside their formulas, after which all the results spill onto the matrix.
Rewriting the CODE
=CODE(MID(C6,SEQUENCE(LEN(C6)),1))
=SEQUENCE(8)
And that’s clearly the more effective and powerful approach.
=CODE(MID(C6,SEQUENCE(,LEN(C6)),1))
That little comma preceding LEN pushes LEN(C6) into SEQUENCE’s second argument, where it moves into column territory.
Looking Ahead
But I do go on. You’ve doubtless gotten the point of SEQUENCE by now, and with just a few practice go-rounds you’ll be a SEQUENCE savant. Now we can pay a visit to another member of the dynamic array crew – UNIQUE.