9.5 SEQUENCE and RANDARRAY
Choose a planned sequence or a variable practice sample
A fictional grocery workshop needs a date for every training shift in November. Those dates should be repeatable. It also needs a collection of made-up orders to test formulas with varied quantities and times. Those values can be generated randomly, as long as the team can save the particular sample it ends up using. Both tasks start with one formula that can supply many cells. The difference is whether the values follow a known pattern or come from a new draw when Excel calculates.
SEQUENCE returns numbers at predictable steps. Specify the number of rows and columns, the starting number and the step between values. RANDARRAY returns random numbers in a requested rectangular shape. Specify the bounds and whether to generate whole numbers or decimals. Both can spill, meaning the results fill neighboring cells from the formula’s starting cell.
The examples use a fictional delivery training roster and invented order figures inspired by shopping examples from Blinkit and Amazon Now. The locations, workflows and numbers are for spreadsheet practice. They do not describe real delivery traffic or actual sourcing practices.
Plan the size and step of a deterministic array
Read the arguments as SEQUENCE(rows,[columns],[start],[step]). Rows gives the height. Columns gives the width. Start is the first number and Step is how much to add from each entry to the next. In the usual one-column case Excel writes the numbers down the sheet. In a multi-column grid it fills from left to right and then starts the next output row. A calculation with the same inputs returns the same numbers. This is what deterministic means here.
| Formula | Shape | First row | Last row |
|---|---|---|---|
=SEQUENCE(5) | 5 rows × 1 column | 1 | 5 |
=SEQUENCE(2,3,10,2) | 2 rows × 3 columns | 10, 12, 14 | 16, 18, 20 |
=SEQUENCE(4,1,9,-2) | 4 rows × 1 column | 9 | 3 |
One reliable check for the last value is start plus step times the number of entries after the first. The two-by-three example has six entries and therefore five later steps. Start 10 plus five steps of 2 gives 20. A four-row sequence starting at 9 with step -2 reads 9, 7, 5 and 3. The chosen direction of change does not change the number of rows. If the design asks for a count down to zero, choose a start, step and number of rows whose actual final result is zero.
Use automatic numbering as a label, not a permanent record key
SEQUENCE is useful for ranking a current result from 1 through its number of rows. If the report reorders the rows, the label 1 still describes the first visible position and may refer to a different order. An Order ID in the source should remain attached to its original transaction. Keep the two fields distinct. A plain generated numbering column is not evidence about when an order first arrived.
Choose the requested kind of random values
RANDARRAY([rows],[columns],[min],[max],[whole_number]) gives a rectangular array when you ask for multiple cells. Use TRUE as the final argument for whole numbers. Use FALSE for decimals. For an integer code from 1 through 6, use the lower and upper endpoints 1 and 6 with TRUE. Repeated draws may return the same code. A set of six draws does not guarantee you will see each code once. Microsoft documents that the minimum must be smaller than the maximum. If a practice need asks for one fixed value, provide that value intentionally instead of passing the same bound twice.
A function that can return fresh values on a workbook calculation is called volatile. The random results may change on recalculation, including after some edits or when opening a workbook with calculation enabled. Consecutive draws can repeat a value, so a single unchanged cell does not prove the workbook stayed fixed. To preserve the sample, copy the results as values to a new area and inspect the actual cells there. This gives both a generator and a frozen input for later work.
Lab 1. Generate a calendar and label its weekends
In a scratch workbook create a Roster sheet. The first report needs every calendar date in November 2026 and a label for each weekday or weekend. The input list does not begin with a typed calendar. You will use a year, a month and a formula for the first date. A second formula uses the number of days in the chosen month.
| Label position | Label | Input position | Value |
|---|---|---|---|
| A2 | Year | B2 | 2026 |
| A3 | Month number | B3 | 11 |
| A4 | First date | B4 | =DATE(B2,B3,1) |
Use a real start date and the actual month length
- Put Date and Shift type in A5:B5. In A6 enter
=SEQUENCE(DAY(EOMONTH($B$4,0)),1,$B$4,1). EOMONTH with a zero offset returns the last date of that month. DAY returns its day number. The resulting 30 is the number of output rows needed for November 2026. - Apply a Date format to the output dates. Excel treats dates as numeric serial values, so adding 1 advances one day for this calendar. You should see November 1 in A6 and November 30 at the end of A6:A35. If the cells show numeric serials instead, check formatting before changing the formula. The underlying values should remain suitable for date calculations.
- In B6 enter
=IF(WEEKDAY(A6#,2)>5,"Weekend","Weekday"). In that WEEKDAY numbering, Monday is 1, Saturday is 6 and Sunday is 7. The condition yields Weekend for Saturday and Sunday. The report returns 30 corresponding labels without needing a fill-down adjustment. - Put the count checks in D6:D8, away from the spill. Use
=ROWS(A6#),=COUNTIF(B6#,"Weekend")and=COUNTIF(B6#,"Weekday"). Expect 30, 9 and 21 respectively. November 1 is Sunday, so the first label should be Weekend. November 30 is Monday, so the final label should be Weekday. - Change the month input to 12. With year 2026 still selected, the report returns 31 dates from December 1 to December 31. Expect 8 weekends and 23 weekdays. Restore 11 after the verification. Check that both reports grew together before reading the new count.
Generate twelve month starts with true month steps
On a separate scratch worksheet, make an April-to-March planning calendar. In A2 enter =EDATE(DATE(2026,4,1),SEQUENCE(12,1,0,1)) and format the result as a date. The starting date is April 1, 2026. SEQUENCE supplies month offsets 0 through 11. EDATE moves by each actual number of months. The twelve dates show the first day of every month, ending March 1, 2027. Check the first three dates are April 1, May 1 and June 1.
Adding a fixed 30 days repeatedly does not express the same rule. From April 1, the next two 30-day steps give May 1 and May 31. The latter is not the first of June. Use a month-aware operation for month starts and daily steps for consecutive dates. These are different units of time. If you need a more limited twelve-day training intake starting September 14, a daily sequence of length twelve ends September 25. Give the report a label showing that the dates are for the fictional exercise.
Trace the calendar from input choice to count
Build the first date
DATE uses 2026, month 11 and day 1 to make 1 November 2026.
Measure the month’s length
The last date is November 30, so the requested result has 30 rows.
Use a consistent weekday numbering
Return type 2 makes Saturday 6 and Sunday 7. Nine dates receive the Weekend label.
Change the month selector
December has 31 dates and eight weekend labels. Both spill columns update from the same calendar.
Lab 2. Generate fifty practice orders and freeze a coherent sample
Create a blank sheet named Generator and a second sheet named Frozen Orders. Set H1 to Number of orders and numeric 50 in H2. In J2:J7 type Pune, Nashik, Nagpur, Kolhapur, Solapur and Sambhaji Nagar, one name per row and with no blank choice. The six names are a lookup list. A random index from 1 to 6 selects a position in that list for each invented order.
Set the six output headings in A1:F1. Order No is a controlled practice number. City, Qty, Mins and Unit Price use random choices for this exercise. Amount is a calculation from the chosen quantity and unit price. Put the following formulas in row 2 and give their spills room through row 51 or farther when you test a bigger source.
| Anchor | Field | Formula |
|---|---|---|
| A2 | Order No | =SEQUENCE($H$2,1,1001,1) |
| B2 | City | =INDEX($J$2:$J$7,RANDARRAY($H$2,1,1,6,TRUE)) |
| C2 | Qty | =RANDARRAY($H$2,1,1,5,TRUE) |
| D2 | Mins | =RANDARRAY($H$2,1,5,25,TRUE) |
| E2 | Unit Price | =RANDARRAY($H$2,1,40,200,TRUE) |
| F2 | Amount | =C2#*E2# |
Check values, sizes and row alignment while the source is live
- Order numbers are predictable from 1001 through 1050. The city values should belong to the six-item choice list. The number of occurrences of each city can vary from one draw to another. A practice sample can have several orders from one city and possibly none from another.
- Verify all six output columns have fifty values. Qty and Mins should be integers, with bounds 1 through 5 and 5 through 25 respectively. A particular sample does not need to contain either endpoint. A minimum quantity of 2 can be valid if none of the current draws were 1.
- Check that each Amount equals Qty × Unit Price for the same row. A generated amount between 40 and 1,000 is possible because 1 × 40 and 5 × 200 supply the bounds. Those endpoints are checks on possible values. The observed total across fifty records can vary. Pay attention to the value associated with the specific order number you checked.
- Keep the size selector and lookup labels out of the result. If you raise H2 from 50 to 60, a result needs ten more rows in each generated column. Check the expected last order number 1060 and verify all six fields grew. Return H2 to 50 for the preserved course exercise.
Preserve one sample independently of the generator
Select the entire current result, including headers, in Generator A1:F51. Copy it as one block. On Frozen Orders, paste starting at A1 using the Values option. Check that the destination contains the six names and fifty complete records. Inspect the formula bar for a few cells, especially one amount. You should find a stored result value. The frozen copy is intended to preserve the entire record, including its random inputs and its matching derived amount. Copying one volatile column at a time risks keeping fields from different calculation states.
Save the source generator and frozen output separately in the workbook. Recalculate the generator using the available workbook commands or make a small edit that recalculates it. Compare a few recorded frozen rows by ID. The generator may change some random values, while the destination copy should not change. Check the source values on one row and verify the preserved amount in the pasted copy still matches its own preserved Qty and Unit Price.
Use a small fixed case for exact totals
Random data lets you explore variety. A fixed case lets several learners compare the same answer. Use these four independent records if you want a known output. They are examples and are not promised results from the random formulas. In the exact case, the Pune amounts add to ₹670 and the full amount is ₹910.
| Order No | City | Qty | Mins | Unit Price | Amount |
|---|---|---|---|---|---|
| 1001 | Pune | 2 | 9 | 60 | 120 |
| 1002 | Nashik | 1 | 12 | 80 | 80 |
| 1003 | Pune | 5 | 25 | 110 | 550 |
| 1004 | Solapur | 4 | 5 | 40 | 160 |
Number a returned list without numbering its empty-state message
Use the fixed four-row practice dataset from the random-order lab on a separate sheet. Put the six columns in A1:F5. Suppose a report should return one city and show a sequence position beside every matching row. Choose the city in I2. Let the result start at K2 and put the separate row numbering at J2. Keep all required cells clear. If Pune is selected, two orders qualify. Their source order numbers stay 1001 and 1003 while their report positions become 1 and 2.
K2: =FILTER(A2:F5,B2:B5=$I$2,"No matching orders")
J2: =IF(COUNTIF(B2:B5,$I$2)=0,"",SEQUENCE(COUNTIF(B2:B5,$I$2)))
The second formula counts matching source rows before asking for a sequence. With no matches it displays no position. If you select Nashik, it displays one position next to order 1002. If you enter Delhi, there is a no-match message and no sequence number. Do not count a fallback text cell as one order. Discarding a generated sequence is preferable when there is no record for it to number.
Keep the source count and output count consistent. If the FILTER rule later adds amount or status tests, update the count from that same condition as well. A simple count by City is correct only while City is the sole selection. Verify the empty branch separately. A friendly status message can still have a one-cell display, whereas zero qualifying order rows is a fact about the data.
Distinguish random labels from selecting unique existing records
The order generator chooses a city many times. Multiple rows can share that city and still have different order numbers. If you instead want to take a practice sample of distinct existing order rows, random integers that point to positions can select the same row multiple times. That is sampling with replacement: each position remains available for every draw. To get a short list without reusing any source position, make a random key per existing record, sort the complete records by those keys, then take the required number of rows.
First run a fixed check using the four known orders. Give 1001 a key of 0.62, 1002 a key of 0.15, 1003 a key of 0.48 and 1004 a key of 0.81. Sorting the aligned records by those four keys puts them in the order 1002, 1003, 1001 and 1004. A selection of the first two rows yields amounts ₹80 and ₹550. The fixed unordered source remains available. Even if two scores are equal, each record is still present only once in the sorted input. Include a unique ID or stored sequence as a later key if you need a deterministic ordering under fixed tied test scores.
In a supporting Excel client, replace the fixed keys with a decimal RANDARRAY of the same height. One example with TAKE is:
=TAKE(SORTBY(A2:F5,RANDARRAY(ROWS(A2:F5),1),1,A2:A5,1),2)
With four unique original order numbers, this returns two different records. Do not predict which two before the draw. A client without TAKE can use the fully sorted four-row random-key result and preserve its first two verified rows as values. If the source itself contains duplicated order IDs, distinct source positions can still share an ID. Verify the input key before using this technique as proof of a distinct record sample.
Save the selected IDs and chosen values when the assignment requires a repeatable output. A sort by fresh random keys can change when recalculated. The formula allows practice with selection and shape. More formal data collection would need its own decision about the population and a record of how the sample was chosen. A larger-looking list alone is not evidence of representative coverage.
Turn the same month into a six-week calendar
A morning roster is convenient as one row per date. A wall calendar usually has seven columns and one row per week. You can build that second view from the same Roster settings without typing each date again. In this practice, keep the existing list at A6:B35. Choose a clear region from F6:L11 for a new output and put Mon through Sun in F5:L5. The 42-cell space can represent six full weeks. The result shows a date only when it belongs to the selected month.
=LET(monthStart,$B$4,
mondayStart,monthStart-WEEKDAY(monthStart,2)+1,
dateGrid,SEQUENCE(6,7,mondayStart,1),
IF((dateGrid>=monthStart)*(dateGrid<=EOMONTH(monthStart,0)),dateGrid,""))
Follow the offsets with one known month
- Compute the first displayed week. November 1, 2026 is Sunday, so WEEKDAY with type 2 gives 7. Subtract seven and add one to move back six days. The first generated date is Monday, October 26.
- Generate weeks across the columns. SEQUENCE returns six rows and seven columns. Each row contains seven consecutive days. The first row runs from October 26 through November 1. The next starts Monday, November 2.
- Keep only dates within the original month. The first row’s Monday through Saturday are outside November, so those cells show empty text. Its Sunday shows November 1. The last week starts Monday, November 30 and hides every following date in that last output row.
- Verify the result against the list. The grid still occupies a rectangle with 42 places. There should be only 30 numeric dates. Use an independent numeric count after applying the display format. Be cautious with COUNTA when the unused positions contain formula-generated empty text. An empty-looking result is not always an empty worksheet cell.
Format the grid as dates, or display only day numbers using a date format suited to the worksheet. The date values still contain the actual year and month. Leave a visible label showing the chosen month since several cells have the same day number in other months. The grid is a presentation view. The one-column date list remains easier to filter or use as a source for the daily schedule.
Test a shorter and a leap-year month
Change the settings to year 2027 and month 2. There are 28 daily entries and the final date is 28 February 2027. Now use 2028 and the same month. There are 29 entries and the final date is 29 February 2028. The month list changes height in each case. The six-week version keeps its reserved width and height, but changes the number of positions displaying dates. Reconcile both versions with the actual month length before restoring November 2026.
Use stable month settings for the handout. A formula based on TODAY can be useful for a live current-month schedule. It changes meaning after a date rollover and recalculation. A reader reopening the exercise later should have the same 2026 fixture if they are trying to reproduce the original answers. Separate a demonstration with a fixed date from a staff schedule that intentionally follows the current date.
Give generated values realistic structure for the practice task
Decide which scale and type the inputs use
The order generator uses whole rupees for its Unit Price field. That is convenient for checking a first workbook. If you need cents or paise, choose a whole-number range in the smaller unit and divide to express the stored amount in the larger currency unit. For an independent example, =RANDARRAY(5,1,300,800,TRUE)/100 returns five values corresponding to an integer number of hundredths from 300 to 800. Display them with two decimal places and check bounds from 3.00 to 8.00. Formatting alone can make decimals look rounded without changing the stored values.
If the practice calculation compares a number with a threshold such as 5.00, decide whether the threshold applies to exact stored quantities or quantities rounded by an explicit approved rule. A display can hide a third decimal. A formula can still use that third decimal. The original exercise avoids this issue by generating integers and using a numeric multiplication. If you switch to decimal prices, document whether to round each order before summing it.
Random fields are not required to follow observed business relationships. A fake city and a fake timing are chosen as simple separate values in this generator. That is enough for testing whether a worksheet filters a category or sums a given date range. It does not establish the typical time in that city. When you need to test a known business relationship, specify constraints or build a deliberately designed edge-case dataset. For example, add one known row at exactly the cutoff to verify whether your condition uses strictly above or includes equality.
Keep generated record fields aligned as the requested size changes
All six columns use the same size control directly or consume an earlier spill that does. If you accidentally hard-code 50 for Qty and configure 60 for Unit Price, both generator formulas can appear valid while the derived Amount no longer represents sixty aligned records. Check the two input dimensions separately. Use the consistent H2 parameter for both and verify the expected new order numbers. A separate first-to-last ID check also helps catch a displaced field, such as the fifth amount belonging to the sixth quantity.
When saving Frozen Orders, compare the minimum and maximum observed amount only after verifying every amount came from the same row’s Qty and Unit Price. A corrupted record could still fall within the allowed range. For a small shared test, verify every row. For the fifty-order sample, build an independent row-level check or compare several exact examples and summarize the number of rows passing. Verify that the saved snapshot has no linked formulas and meets the same validation controls.
Test parameter values before asking for a longer array
Use actual weekday positions for recurring sessions
The roster may ask for Mondays only. In a clear scratch region, try =SEQUENCE(6,1,DATE(2026,11,2),7). It begins on Monday, November 2 and takes steps of seven days. The next dates are November 9, 16, 23 and 30, then December 7. Six requested positions contain only five November dates. To create a report for November only, keep the selected dates within November’s boundaries. The count of records and the date interval are separate choices. A shape check and a last-date check together can catch an off-by-one practice setup.
If someone wants a horizontal row of those exact dates instead, set one row and six columns while keeping the same start and step. The values do not change. The area required changes from six vertical cells to six horizontal cells. Choose a layout according to how downstream formulas consume the result. A dataset with one session per record is often easier to use as a list. A display with a separate day heading over each column may call for the horizontal form.
Restrict input settings to the calendar you intend to build
In Roster the Month number should be a whole number from 1 to 12. Excel’s DATE function can carry larger month numbers into the following year. If you type 13 while Year is 2026, the underlying start becomes January 1, 2027. The next formula can still show a valid January calendar, even though the entered month does not belong to the selected year. An input validation rule or a simple visible check for the range 1 through 12 helps catch that mismatch before someone reads the report.
Verify the current settings by comparing the first date’s displayed month and year with the labels. Changing a valid year affects leap days and which weekdays dates fall on. Changing the month affects both dimensions and the start value. A calendar may have the correct count of 31 days while having the wrong month entirely. Inspect the first day, the last day and one known weekday near the boundary to make sure the repeatable report is reading the intended inputs.
Give random tests both a fixed control and variation controls
To train a coworker, use the four known rows to verify a formula such as “Pune amount” separately from the fifty random rows. The known result is ₹670. It should be reproducible even after opening the workbook later. After confirming that calculation, run it on the frozen fifty-row sample and record its source version and observed amount. A different fifty-row draw may have a different number of Pune orders. That difference can be correct because the inputs differ, so compare record membership before investigating the formula.
On Frozen Orders, make a separate control outside the six pasted fields. For example, write =F2=C2*E2 beside the first record and fill the check through row 51. Every row should evaluate to TRUE. Verify that the copied ID column has fifty distinct values and inspect the first and last. A repeated city is normal in the generator. A repeated order number would violate the intended test record design. These checks catch a wrong copy boundary or a displaced field even if the amount total looks reasonable. The workbook needs no exact predicted grand amount for the fifty-row case, because it varies with the draw. Once frozen, record the observed sum so returning to the same dataset remains verifiable. Also record the sample’s first and last order numbers so someone can compare the stored range without opening the generator formulas.
When the workbook generator is designed to support repeated workshops, ask learners to preserve one validated sample per exercise. Include the size setting and allowed values in a short note. Do not assume a copied file with the live generator will reproduce the same draw. Keeping the independent fixed control next to the actual selected sample lets the next person distinguish a formula defect from a newly generated dataset.
Troubleshoot size, type and volatility separately
- Dates show as numbers. Verify the starting date formula and apply a Date format to the output. Test the first and last actual calendar dates rather than replacing the numeric source with text.
- The final date is in the wrong month. Check whether you are taking steps by days or months, and inspect the computed month length. A 30-day step and a one-month move are different operations.
- The last practice ID is wrong. Check whether the sequence includes the starting value and uses one step less than the count of values. Fifty IDs starting at 1001 end at 1050.
- The generator produces a value error. Check that the minimum is smaller than the maximum and that you gave valid size input. In the practice formulas use a known positive integer row count.
- The result stopped spilling after increasing the size. Inspect the intended target. Move independent text or formula cells away from the new shape. A random value can vary while the dimensions remain fixed.
- The numbers keep changing. Confirm you are viewing the generator sheet, then compare its frozen values copy. Recalculate the generator and verify the frozen sample itself still contains stored values.
Microsoft gives a specific example of an unstable array size: a SEQUENCE whose row count changes during calculation through a random number function. The output size may fail to stabilize and can produce a spill error. The order generator deliberately uses a known count in H2. This makes every random input share the same number of rows. Randomize contents only after defining the stable shape you actually need.
Quiz. Predict a known value or a valid bound
What does SEQUENCE with 2 rows, 3 columns, start 10 and step 2 return last?
20. There are six values. The last is five increments after the starting 10. The last row contains 16, 18 and 20.
Why should the calendar produce 30 results for November 2026?
The last actual date of that month is November 30, whose day number determines the required row count. The first is November 1 and a step of one gives each calendar date.
Which WEEKDAY results count as weekend with return type 2?
Saturday is 6 and Sunday is 7, so the rule checks for numbers above 5. The November exercise has nine weekend dates.
Does RANDARRAY with five integer outputs from 1 to 5 return each integer once?
No. Each draw can repeat a value, and some possibilities may not appear in a small sample. Verify the count, type and bounds.
Why paste the generated rows together as values?
It preserves one set of inputs and its matching derived amounts. Recalculating between separate column copies could produce inconsistent records. Check a few pasted amounts against their preserved quantities and prices.
Which result proves a no-match label is not an order?
The zero-match City test has no matching source record, so the independent count is zero and the ranking sequence should be empty. The descriptive message is for the reader.
Interview practice. Explain shape and repeatability
When choose SEQUENCE instead of RANDARRAY?
Use SEQUENCE when values must follow a predictable step, such as dates, positions or practice IDs. Use RANDARRAY when varied practice inputs are useful. Keep the allowed bounds and expected size explicit in either case.
How do you preserve one set of fictional data for other students?
Generate the full set in one clear region, validate count, types and formulas, then copy the full result as values to an independent destination. Compare its exact IDs and calculated values after recalculating the generator.
Why use EDATE for each month in a monthly schedule?
It moves by calendar months, so starting on the first produces subsequent first days. A constant number of days can fall in the wrong month because actual month lengths differ.
What should you test when a random setup supposedly returns 50 records?
Verify independently that all columns contain 50 values and that the order IDs cover the expected interval exactly. Check bounds for numeric inputs and compare a derived amount with its row’s quantity and price. There is no promised exact random total.
How do you avoid picking the same source row twice in a small exercise sample?
Sort complete source records using one random key per row, then take the intended number of rows. Confirm source IDs are unique if the business requirement is distinct order IDs. Preserve the selected rows as values for reproducibility.
Revision cards
- SEQUENCE. Set rows, columns, start and step. Predict the final number.
- Date serial. A step of one moves one day. Use a month-aware function for month advances.
- RANDARRAY. Choose bounds and integer mode. Repeated draws can repeat values.
- Clear shape. Reserve enough cells for the intended number of rows and columns.
- Values snapshot. Preserve a complete draw by using Paste Values on a separate sheet.
- Generated position. Number a live output separately from the underlying record identifier.
Microsoft references
Continue practising: explore the existing Excel Task Hub for additional exercises.