Ravindra BagaleCourses & study guides मराठी Track your progress

9. Dynamic Arrays

Excel

9.1 Spill Ranges and the # Operator

Follow an expanding list without changing its address by hand

A fictional grocery coordinator needs a current list of delivery cities. Ten orders contain repeated names, so copying the City column and manually deleting duplicates would create a separate list to maintain. A formula using UNIQUE can return one copy of each city from the current source. Tomorrow an order may add another city. The list needs to grow, and a count elsewhere in the workbook needs to refer to the whole result, even though nobody knows its final row number today.

Excel can place several results from one formula in neighboring cells. This process is called spilling. The starting cell with the editable formula is the anchor. The output cells together form the spill range. If the anchor is K2 and six cities appear down the column, the result occupies K2:K7. Write K2# to refer to the whole current spill from K2. This lets a separate calculation read the output while the last row changes. The number sign in a reference is Excel’s spilled range operator.

The first lab uses the imaginary grocery order list inspired by Blinkit and Amazon Now. The second uses numbered viewing passes in a made-up media club practice scenario inspired by Netflix. No figures or processes describe those businesses. Both examples use tiny inputs so you can verify the whole shape from the first cell to the last.

Read the spill as a rectangle

Count rows and columns before you choose the anchor

Result dimensions tell you how far Excel must place values down and right. A four-row result that is one column wide needs four addresses in the same column. A three-by-two result needs three rows and two columns, occupying six cells. Excel starts the rectangle at the anchor, so a three-by-two result at F3 uses F3:G5. You can work out that boundary without using a formula: begin at row 3, include rows 3, 4 and 5, and include columns F and G.

An array formula can fill more rows, more columns or both depending on its inputs. A list of distinct cities is taller than it is wide. Row-based report filters may return each matching record with several fields. A people count, amount total or a summary label needs one result. Choose the dimensions that match the requested purpose. If the formula includes headings in its input array, those headings contribute cells to the result unless you explicitly handle them.

Find the editable cell and the output cells

  • Anchor. Only the top-left formula cell controls the whole result. In F3:G5, edit the formula at F3. If it should start elsewhere, choose a clear destination and re-create the formula there using the intended inputs.
  • Generated output. Selecting a result within the spill can show the anchor’s formula in a dimmed or ghosted state in the formula bar. You cannot edit just one generated value as though it were an unrelated worksheet cell. Edit the original input or the formula at its anchor.
  • Output border. A successful spill can show a border around the result when selected. Let that outline confirm the actual extent. A blocked formula can show a different indicated boundary for the cells it intended to use.
  • Consumer. A separate formula like =ROWS(F3#) uses the live result. Put it outside the spill’s possible extent so the counting formula cannot become the blocker when the output grows.

Excel uses a number sign in other contexts too. The # on the end of F3# asks for the full spill from F3. It is separate from a Table’s structured reference specifier such as #Headers, which designates an area of a Table. It is also separate from the leading symbol in an error such as #SPILL!. Read each symbol within its complete expression.

A single anchor in F3 produces a three-by-two result through G5. It contains 101 and 102 on row 3, 103 and 104 on row 4, and 105 and 106 on row 5.
The generated rectangle includes the anchor and five additional values.

Choose a live result or a fixed address deliberately

If six cities currently appear at K2:K7, the expression =COUNTA(K2:K7) counts nonempty cells in those six positions. It can produce the correct answer now. When a seventh city spills into K8, the range still stops at K7. When the result shrinks, that fixed reference stays the same length and may later read other values placed there. The spill reference K2# follows the area actually produced by the formula. Use the actual anchor rather than a cell somewhere in the middle of the result.

Use a reference to a spill only when the formula can produce the intended result successfully. If its input formula is blocked or produces an error, a downstream formula cannot read the unavailable spill as if it were an empty successful list. Diagnose the anchor first. A summary can be safely given a separate no-record policy when you understand why it is empty. Avoid using an error handler that turns every error into a blank without preserving the place to inspect the cause.

Choose the count by its meaning. ROWS() gives the number of rows in the referenced result. COUNTA() counts nonempty values across all referenced rows and columns. In a single-column list with no missing values, the two may agree. In the numbered pass grid, three rows contain six numbers. In a report with a text fallback or headings, a row count need not be a record count. A separate check such as a count of qualifying IDs can clarify the result.

Lab 1. Grow a unique list into a deliberately blocked cell

In a scratch workbook, create the following list in A1:C11 on a sheet called Orders. It uses the Chapter 3 source’s example cities and categories. Convert exactly A1:C11 to a Table with headings and call it tblSpill where your client provides the name control. Leave the free grid from J1 through P20 available for the outputs and temporary test note.

Orders A1:C11. The source has one row per order.
Order IDCityCategory
BLK-1001PuneDairy
BLK-1002NashikFruits
AMN-1003PuneSnacks
BLK-1004NagpurFruits
AMN-1005KolhapurDairy
BLK-1006PuneBakery
BLK-1007SolapurHome
AMN-1008Sambhaji NagarStaples
BLK-1009PuneSnacks
BLK-1010NashikFruits

Establish the first successful layout

  1. In K1 write Cities. In K2 enter =UNIQUE(tblSpill[City]). Expect K2:K7 to show Pune, Nashik, Nagpur, Kolhapur, Solapur and Sambhaji Nagar in their first-seen order. Confirm K2 is outside the named Table and the six values occupy one column.
  2. Put =ROWS(K2#) in M2 and =COUNTA(K2#) in M3. Each shows 6 because the result has six populated cells in six rows. Use N2 for =SORT(K2#). It should show Kolhapur, Nagpur, Nashik, Pune, Sambhaji Nagar and Solapur. This second formula stays in its own clear column and follows the first output.
  3. Click K5 and inspect how the formula bar shows the inherited output. If you want to change the formula, return to K2. Do not try to overwrite an output cell already occupied by the spill. K8 is below the current result and is still available for the next test.

Make the output grow into a note

  1. In K8 type Keep this practice note. The six-city result should still fit because it currently ends at K7. Preserve the note for the growth test. A cell that is free now can become necessary when new categories arrive.
  2. Enter an eleventh source record, AMN-1012, Satara, Beverage, in A12:C12. Verify it joined tblSpill. Satara is new and supplies the seventh value, so the intended city output now reaches K8. The note is in the way and the formula at K2 should show #SPILL!.
  3. Select K2 and inspect the intended area. The problem is in the output, even though the new source record has the correct fields. Where available, use the error menu’s obstructing-cell selection. Move the note from K8 to P2 in the scratch workbook. Check that both the note and the city list survive in their correct places.
  4. Verify the recovered K2:K8 range and the two counts of 7. N2 now sorts seven cities. Satara appears after Sambhaji Nagar and before Solapur in this alphabetical exercise. The separate source list now contains eleven orders, so the distinct count of seven is a different measure from the source count.
The original six cities use K2 through K7 and leave a note in K8. A seventh city needs K8. Move the note and K2 hash includes all seven cities.
The note is outside the first result and inside the expanded one. Check the intended boundary after a source edit.

Follow the spill through one source update

  1. Return six unique cities

    K2:K7 is occupied. A separate note in K8 does not affect this result.

  2. Add a new city to the actual Table

    Satara introduces a seventh city. The intended result must reach K8 and cannot because the note is there.

  3. Move the note out of the result area

    Place the note elsewhere and watch K2:K8 fill. The counts linked to K2# now read seven.

  4. Change that new member to an existing city

    If its city becomes Pune, the distinct city list shrinks to six even though the Table still has eleven orders.

Use a second field to prove the anchor determines the measure

In L2 enter =UNIQUE(tblSpill[Category]) with clear space below. The original categories are Dairy, Fruits, Snacks, Bakery, Home and Staples. Beverage supplies a seventh after the append. In M4 use =ROWS(L2#). Then change the new order’s city from Satara to Pune and leave its category as Beverage. The count from K2# drops to 6. The count from L2# stays 7. Neither formula edits the source rows. It is reading a changing number of distinct values from its own input field. Restore Satara if you want to repeat the growth test later.

Lab 2. Change both dimensions of a numbered pass grid

A media club wants a small grid of sequential numbers for an imaginary screening practice. The sheet starts with three rows and two columns of sample numbers. Later the organizer wants another row and another column. This workbook exercise checks how a report can consume a changing rectangle. The numbers are arithmetic examples, not actual ticket identifiers.

Put these labelled controls on a fresh sheet named PassGrid.
Label cellLabelInput cellInitial value
A2RowsB23
A3ColumnsB32
A4StartB4101

Use one formula and a few independent checks

  1. In F3 enter =SEQUENCE($B$2,$B$3,$B$4,1). The arguments give the rows, columns, first value and step of one. Excel should return 101 and 102 in the first row, 103 and 104 in the next, then 105 and 106. Locate the last result at G5. You can see the values increase across one row before continuing on the next.
  2. In K3 use =SUM(F3#), in K4 =ROWS(F3#), in K5 =COLUMNS(F3#) and in K6 =COUNTA(F3#). Expect 621, 3, 2 and 6 respectively. These measures distinguish the count of rows from the count of all values. Keep all four checks outside the intended expansion area.
  3. In K7, test =INDEX(F3#,2,2). INDEX picks the second row and second column of the result. You should see 104. It is the value at G4. No separate formula was entered in G4. If the query were “last seat number on row 2,” make sure the column argument describes the final column for that particular shape.

Predict a new footprint, then test the larger rectangle

Change B2 from 3 to 4 and B3 from 2 to 3. The result now occupies F3:H6. It should start at 101 and finish with 112 in H6. Check all four result measures: sum 1,278, rows 4, columns 3 and nonempty values 12. The second row now contains 104, 105 and 106. INDEX at row 2, column 2 gives 105. A named position and its displayed value can change as the shape evolves.

Compare with =SUM(F3:G5) only for the newly expanded result. That fixed range now reads the values 101, 102, 104, 105, 107 and 108, adding to 627. It leaves out the third column and fourth row. It also reads different values in some positions than the original small spill. This distinguishes a fixed portion of a changing result from a fixed snapshot of earlier numbers. If you need the exact first six numbers as a prior record, copy the small result as values to an independent destination before expansion.

Try a width blocker without entering a current result cell

Restore B2 to 3 and B3 to 2. Put a temporary note in H4, which is just to the right of the current output. Change B3 to 3. The three-column result needs F3:H5 and now intersects H4, so the formula shows a spill error. Move the note to a different area such as K9 where it cannot block the result. Verify nine values ending at 109 in H5. Restore the two-column input and check the outputs and test notes before closing the scratch workbook.

Choose when the formula should return one value

Modern Excel’s @ is the implicit intersection operator. It can reduce a range or array expression to a single value. For a referenced range it selects the cell in the matching row or column when Excel can identify one. For an array value it takes the top-left entry. These cases are different from #, which refers to a successful spill. Use the operator in a full expression rather than deciding that either symbol is needed merely because a formula looks new.

Try two different one-value cases in a clear area

In PassGrid A10:A12 enter 7, 8 and 9. In D11 enter =@A10:A12. The formula’s row matches the middle source row, so the result is 8. Now enter =A10:A12 in an empty region such as F10 with F10:F12 clear. The dynamic array result is 7, 8 and 9. The same source addresses fed two different requested output shapes.

An array produced within a formula is another useful case. In K11 use =@SEQUENCE(3,2,101,1). With this array the operator keeps the top-left 101 as one result. If you need a specific position other than the first item, use a clear selection such as INDEX with known row and column arguments. If you need the complete matrix, keep the formula in a clear grid region and use the full output. Check the purpose before removing an automatically added @ from a migrated formula.

Understand old workbook behavior before rewriting it

Excel has earlier array formulas entered with Ctrl, Shift and Enter on relevant desktop builds. Excel displays them with braces and their output range may be fixed at the time of entry. Modern spilling formulas use one formula entry at the anchor. An old workbook may be intentionally designed around earlier behavior. Save a copy and verify dependencies and output size before converting its formulas. Entering braces by hand is not how a modern spill is created.

When a modern Excel version opens an older expression that depended on implicit intersection, it can show the @ explicitly to preserve that behavior. A pre-dynamic Excel version can represent a modern explicit intersection formula differently, such as with _xlfn.SINGLE() in some cases. Test the actual target client. Avoid giving coworkers a formula file that relies on a new function without checking if they can calculate it.

Feed one result into another formula without assuming its size

Give the second output its own anchor

In the PassGrid lab, the numbered rectangle is useful as a source for another result. Suppose the media club wants a prefix on each practice number. Put a new formula in N3 after confirming there is free space through P6. Use ="PASS-"&TEXT(F3#,"000"). TEXT turns the array’s numeric entries into text using a three-digit display pattern, and the ampersand joins each one with the prefix. Verify N3 begins with PASS-101. For the initial three-by-two rectangle, O5 is PASS-106. Check that the source in F3:G5 still contains numeric values that can be summed. The two outputs use different types and share the same shape.

  1. With three rows and two columns, use =ROWS(N3#) and =COLUMNS(N3#) in cells well outside both potential spill areas. Expect 3 and 2. Confirm the first and last labels and do not use a numeric total of the text labels as a validation.
  2. Temporarily set the Start parameter B4 to 7. The first numeric entry becomes 7. Its label becomes PASS-007. The starting number and its display label have different meanings. Verify that no leading zeros are lost in the label snapshot. Restore 101 after testing.
  3. Increase the size to four rows and three columns. F3:H6 then supplies all twelve numbers. The label formula also needs four by three and fills N3:P6. Its last label is PASS-112. That means both formulas and their dependents need room to expand.
  4. Restore the two-column size. Recheck both outputs. In this scratch layout the check formulas did not need an address change. The named spill reference was able to follow the first array as it expanded and then contracted.

The prefix formula helps distinguish a stored number and a derived string. If someone uses a label as a lookup key in another report, choose an agreed prefix and starting-number policy. A generated list of practice pass labels is not a durable record of issued passes. The values can all change when the parameters change. A static record should preserve the known values or capture a separate identifier at the time the record is created.

Check the final output shape even when a formula uses an array

An expression can construct six values as an intermediate step and still return one number. In a clear scratch area, compare =SEQUENCE(3,2) with =SUM(SEQUENCE(3,2)). Enter them far apart. The first returns the numbers 1 to 6 into six cells. The second calculates the same six numbers inside SUM and returns one result, 21. There is no six-cell external spill to attach the # reference to for that single-number summary. Consult the last operation in the full expression, rather than deciding its size from the name of an inner function.

This distinction matters for a Table calculated column. A per-record expression can use a suitable calculation and still return one value for its row. A multi-row dynamic report needs a separate ordinary worksheet region. The fact that both formulas read a named Table column is not the deciding feature. The difference is the output required by the expression. Use an independent dimension check when a formula should become a report rather than a row value.

If you need to inspect the six intermediate numbers, temporarily put just the inner SEQUENCE expression in a separate scratch area. Compare its shape, top-left number and final number before relying on the scalar result. That is a simple way to debug a more involved formula where invisible intermediate arrays can have shape or alignment mistakes. After verifying the test, keep the result where it serves the report and remove the separate scratch calculation if it is unnecessary.

Handle a requested field that might be outside the result

Suppose the organizer wants the second row’s third pass, if a third column exists. In a clear single-result cell use =IF(COLUMNS(F3#)<3,"No third column",INDEX(F3#,2,3)). The check assumes at least two rows in this practice. With two columns, the formula shows the message. With three columns and the original Start 101, it yields 106. Row 2 contains 104, 105 and 106. A user can see that the missing third field is a deliberate consequence of a smaller grid instead of a general formula failure.

Read those position arguments relative to the array’s own top-left cell. The second row of a spill anchored in row 3 is worksheet row 4. If you move the same formula to row 12 and keep the same input, the second array row is now worksheet row 13. The position within the result is still two.

You can check a whole column position when it exists. After expanding the practice grid to four rows and three columns, a sum of the third column’s four values is 103 + 106 + 109 + 112 = 430. For instance, =SUM(INDEX(F3#,0,3)) uses zero for the row selector to supply that whole column. This continues to summarize the third result field, so only use it in states where that column exists. A shape check before the calculation is useful when an upstream result can contain fewer fields. In a real report, also check what the column means if the source schema can change.

Verify a spill’s smaller and larger states independently

Readers sometimes add a new heading directly beneath a formula because the latest result only covers a few rows. Later a valid source addition makes that heading part of the intended range. Keep notes in a separate region or fixed side panel. The city example makes the issue concrete: at six cities K8 is free, and at seven it is a required result. A reader seeing only the earlier display cannot infer the later boundary. A note outside both current and expected future results is easier to preserve.

Plan a three-step expansion proof

  1. Document the current extent. Write “K2:K7, six distinct cities” in a separate place. In a grid case record both dimensions, such as F3:G5, three rows and two columns.
  2. Change exactly one input. For the city list append a new distinct city. For a width test keep the number of rows and move from two columns to three. Before opening the workbook, mark the new last address on paper. A known future address makes the observed spill border easier to interpret.
  3. Check the dependent result. After resolving any blocker, verify the new count, first or last entry, and any downstream calculated figure. Then restore the smaller state and see what changed. A copied observation can preserve the old values for comparison, while a new calculation using # follows the latest result.

Test a merged-cell blocker without touching a real report

On an unused scratch sheet, leave B2:C4 empty and merge just B4:C4. Place =SEQUENCE(3,2) in B2. Six intended values must reach B4 and C4. Even a merged area visually containing nothing can stop the three-by-two output because it cannot allocate both cells separately. Move the test formula to F2 where both columns and three rows are clear, or unmerge the deliberate scratch cells. Check the successful first row is 1 and 2 and the last row is 5 and 6. Do not remove formatting from a live report just because the scratch case was blocked.

In the rebuilt report, check that the output sits in ordinary cells and stays inside the worksheet. You can keep the report labels above the first data row as long as the result only needs cells below and to the right of its anchor. A title merged across several columns well outside the generated rectangle can coexist with a spill. It becomes relevant only if the chosen anchor or future shape puts generated values into that area.

The same inspection method applies when several dynamic reports share a worksheet. Put each one in its own reserved rectangle, with clear headings and a location for checks outside those rectangles. If cross-report outputs might have unpredictable dimensions, use separate tabs or use a controlled shape transformation before stacking them. Keep a readable map of data source, formula start and expected result headings. This makes it possible to reproduce a failure without clearing someone else’s sheet.

Debug and place a spill without losing other work

Locate the intended result before moving a blocker

  • Visible note or label. Compare its address with the error’s intended rectangle. Move the note to an appropriate clear area of the practice sheet and verify it still exists.
  • Blank-looking cell. A formula such as ="" appears blank but occupies its cell. Inspect the formula bar. If the apparently empty result is important elsewhere, move the new anchor to a clear position rather than clearing the older formula.
  • Merged cells. A merged range may block a spill even when the merged cells show no text. Move the new formula to an unobstructed rectangle, or unmerge in a practice copy and verify the result.
  • Excel Table. Spilled array output cannot live inside the Table. Place its anchor in a normal range, and keep using structured references if you want the Table’s fields as inputs.
  • Sheet edge. If the desired width or height would run outside the worksheet, move the anchor or give the formula a bounded actual input. An entire-column reference can request far more outputs than the author intended.
  • Unstable output size. Microsoft documents examples where volatile formulas keep changing the requested dimensions during calculation. Use a deliberate numeric size control in the practice workbook and prove the output fits.

Use a disposable sheet to try one extra blocker without editing a current spill. Start with a clear M3:N4 and put ="" in N4. Enter =SEQUENCE(2,2) in M3. The desired values 1, 2, 3 and 4 require those four cells and run into N4. Move or clear only the deliberately placed formula after confirming the address. Then M3:N4 should show two rows with a total of 10. A cell’s displayed label and whether it occupies a spill destination are different questions.

Hiding the column of a blocker is not a substitute for moving it. The cell still belongs to the worksheet and has content. If a separate report needs a manual notes column, position that note column outside the maximum planned width. Keep notes keyed to the actual ID rather than forcing one cell in a dynamic result to retain a specific record forever.

Verify dependencies before moving or deleting an anchor

Other formulas can depend on the anchor through K2#. If you clear K2 before replacing it, the consumers can show errors until you put the intended producer back. Keep a small worksheet map of the anchor, the intended source and the consumer addresses. Move or replace the anchor only in a scratch copy while testing. When you choose a new anchor such as R2, adjust the dependent expressions to match, or check whether your particular move operation updated them. Confirm both the actual spill and the independent summaries after the change.

Check the source file if the result depends on another workbook

Microsoft states that the spill range operator does not support closed workbook references. The related dynamic array documentation describes limited support between open files and possible #REF! on refresh when the source is closed. A formula result that loaded once while the source was open can become unavailable later. If the workflow needs to operate without the other file, use a verified local input Table or a documented import, or make a static output after confirming exact IDs and values.

Quiz. Diagnose the spill shape

Where do the four rows and three columns from F3 fit?

The target is F3:H6. It starts at column F and row 3, then extends through H and through row 6. K3 and later check cells are outside that rectangle.

Why can a note in K8 coexist with the first city result but block the second?

The first six cities occupy K2:K7. The seventh distinct city makes the intended result reach K8. Move the note outside the expanded area. Then the original formula can return all seven.

What changes when K2# grows from six to seven populated entries?

ROWS and COUNTA linked to it both become seven in this one-column case. A fixed reference ending at K7 still reads only six cells. The source appending an eleventh order is a separate record count.

Which cell changes generated value 104 in G4?

The formula at F3 produces G4’s result. Edit the anchor or alter its size and starting inputs. G4 is one generated value, so it is not separately editable while the spill exists.

When does the one-value intersection example give 8?

In D11, the A10:A12 reference intersects worksheet row 11 at A11, which contains 8. A formula asking for the entire range in a clear ordinary grid can produce three values.

Why can a blank-looking cell still be a blocker?

A formula that returns empty text still occupies its cell. If it is inside the intended spill area, move the new formula or preserve the existing calculation elsewhere in the practice sheet.

Interview practice. Explain a reliable dynamic layout

How would you grow a distinct-city list safely?

Use the verified City data body of a Table as input, put UNIQUE at a clear anchor outside the Table, and verify its spill reference after appending a known new city. Keep count formulas outside the possible output and test whether a duplicate city leaves the distinct count unchanged.

Why use both a fixed copy and a spill reference in one workbook?

The spill reference suits calculations that should follow the live result. A verified pasted-values copy preserves a past result for comparison. One can grow and reorder, and the other records the exact earlier set under documented criteria.

Which evidence distinguishes a source failure from a destination blocker?

Confirm the source really contains the new qualifying row and the calculated result requires a known shape. Inspect the requested destination range. In the example, moving K8’s note restores the correct output without changing the source.

Why can adding @ change a report rather than fix it?

The operator can reduce a reference or array to one value. That suits a formula designed for a single output. It discards the larger result the report may need. Specify whether the requirement is one value or the complete spill before using it.

How would you check the output after changing a table schema or moving an anchor?

Record the intended fields by name, verify the output dimensions and the first and last records and update the dependent formulas to point to the correct anchor. Test a grow and shrink change with a clear destination and check the external dependencies if there are linked files.

Revision cards

  • Anchor. The first cell contains the editable formula for the entire result.
  • Shape. The output has a definite number of rows and columns.
  • Hash. Add # to the anchor reference to follow the successful spill.
  • Blocker. Check occupied and merged cells in the intended rectangle.
  • Current value. Use @ only when you need the single value chosen by intersection.
  • Growth. Keep the source structured and give the output a clear ordinary grid.

Microsoft references

Continue practising: explore the existing Excel Task Hub for additional exercises.