How to Dynamic Range Between Two Matches in Excel
Learn multiple Excel methods to dynamically capture and use the cell range that sits between two matching markers, with step-by-step examples and practical applications.
How to Dynamic Range Between Two Matches in Excel
Why This Task Matters in Excel
In many day-to-day workbooks we store events, transactions, or milestones in a single list. Frequently, we need to isolate everything that sits between two markers — for example, everything between “Project Start” and “Project End”, or all rows between the first “Error” and the next “OK”. Rather than filtering manually each time the data grows, a dynamic formula (or named range) that automatically expands or contracts based on those markers saves time and removes human error.
Imagine a production log where each machine’s “ON” and “OFF” states are recorded down a single column. Quality engineers often need the temperature readings between those two states to calculate average operating temperature. Financial analysts might store account balances by date and want the range between the first day of a quarter and the last. In marketing, you could list campaign phases and quickly pull everything that occurs between “Launch” and “Wrap-Up” for reporting.
Excel is ideal for this problem for three reasons:
- Powerful lookup and array functions such as MATCH, INDEX, FILTER, OFFSET, and newer helper functions like TAKE and DROP let you build a solution entirely in-cell without VBA.
- The workbook can recalculate instantly when new data is appended, ensuring your dashboards and KPIs always reflect the latest period.
- The same logic can feed conditional formatting, charts, data validation, or Power Query, reinforcing a single source of truth throughout your model.
Failing to master this technique often leads to brittle helper columns, manual copy-paste steps, or error-prone SUBTOTAL filters that break the moment a colleague sorts or inserts rows. Learning a dynamic, formula-based approach makes you faster, keeps your worksheets lighter, and builds skills that translate directly to other lookup and array challenges in Excel.
Best Excel Approach
Two broad approaches cover almost every version of Excel:
- Modern Dynamic Arrays (Microsoft 365, Excel 2021): Use FILTER combined with MATCH (to locate row numbers) and INDEX (to convert those positions into valid ranges). Because FILTER natively spills a result, the output automatically resizes.
- Classic Formula (Excel 2019 and earlier): Build a dynamic named range or formula using INDEX and MATCH for the first cell and INDEX and MATCH for the last cell, then use INDEX:INDEX notation ([A1]:[A10]) to represent the entire range. This works everywhere, including pivot tables, charts, and older Excel versions.
The logic is identical:
- Find the row number of the first marker.
- Find the row number of the second marker.
- Return the cells that sit between those rows (inclusive or exclusive depending on your requirement).
Recommended modern formula (inclusive):
=FILTER(Data, (SEQUENCE(ROWS(Data))>=MATCH(StartMarker,Data,0))*
(SEQUENCE(ROWS(Data))<=MATCH(EndMarker,Data,0)))
Classic dynamic range (exclusive) named “BetweenMarkers”:
=INDEX(Data, MATCH(StartMarker,Data,0)+1) :
INDEX(Data, MATCH(EndMarker,Data,0)-1)
Choose the modern FILTER approach when you have Microsoft 365 or Excel 2021 and want an immediate visible spill range you can use downstream. Select the classic INDEX:INDEX approach when you must maintain backward compatibility or feed the range directly to legacy tools that do not accept spilled arrays.
Parameters and Inputs
- Data – A single-column or multi-column range that contains at least one instance of both markers. Use structured references like Table1[Event] for clarity.
- StartMarker / EndMarker – The exact text, number, or date that signifies where the range begins and ends. They can be cell references or hard-coded literal values in formulas.
- Inclusive vs Exclusive – Decide whether to include the rows containing the markers themselves. Adjust the
+1or-1elements in classic formulas, or the comparison logic in FILTER. - Multiple Occurrences – MATCH returns the first occurrence by default. If your data may contain duplicates and you need the last occurrence, wrap MATCH in XMATCH with the
-1last-to-first mode (modern Excel) or use LOOKUP with a large lookup value. - Data Type Consistency – Ensure your markers are of the same type as the values in the data column (dates stored as true dates, not text).
- Error Handling – When either marker is missing, the formula should return a friendly blank or message. Use IFERROR or the optional
[if_empty]argument in FILTER.
Step-by-Step Examples
Example 1: Basic Scenario
Suppose we have temperature readings in [A2:A25]. The word \"ON\" marks when the machine starts and \"OFF\" marks when it stops. We want the temperatures between those two states, excluding the markers themselves.
Sample setup:
A1: Log
A2: ON
A3: 71.5
A4: 73.1
A5: 74.0
A6: OFF
A7: ON
...
Step-by-step:
- Convert [A1:A25] into an Excel Table named
Log. This makes formulas easier to read. - In [E2] type the marker ON, and in [F2] type OFF.
- Enter the formula below in [H2]:
=FILTER(Log[Log],
(SEQUENCE(ROWS(Log[Log]))>MATCH(E2,Log[Log],0))*
(SEQUENCE(ROWS(Log[Log]))<MATCH(F2,Log[Log],0)))
Explanation:
SEQUENCE(ROWS(Log[Log]))produces [1,2,3,...] for every row.- The logical test creates TRUE where the sequence number is greater than the ON row and less than the OFF row.
- Multiplying the two logical arrays creates an AND operation. FILTER returns only rows where the product is TRUE.
Expected result: rows [A3:A5] spill into [H2#], containing 71.5, 73.1, 74.0. Any new reading inserted between ON and OFF automatically appears.
Troubleshooting tips:
- If no result spills, verify that both markers exist and that ON appears before OFF.
- If you see a
#CALC!error, you may have duplicate markers or overlapping sequences.
Common variation: Include the markers by changing the comparisons to >= and <=.
Example 2: Real-World Application
A retailer tracks promotions in a column called Stage inside an order detail table Sales. The stages are \"Pre-Promo\", \"Promo\", and \"Post-Promo\". Analysts need every order that occurred during the Promo window — defined as everything between the first \"Promo-Start\" and the next \"Promo-End\" row — even if several thousand orders sit in between.
Data layout:
- Column A: Stage (labels such as Promo-Start, Promo-End, or blank)
- Columns B-H: Order details (Date, SKU, Units, Revenue, etc.)
Business logic: Include records from the first order record after Promo-Start up to the last record before Promo-End across all columns.
Steps:
- Set up two helper cells:
- [K1] label: Start Stage
- [K2] value: Promo-Start
- [L1] label: End Stage
- [L2] value: Promo-End
- Enter this formula in [N2]:
=FILTER(Sales,
(SEQUENCE(ROWS(Sales))>MATCH(K2,Sales[Stage],0))*
(SEQUENCE(ROWS(Sales))<MATCH(L2,Sales[Stage],0)))
Because Sales is a whole table, FILTER will return every column, not just Stage. The marketing analyst can now create a pivot on N2#, summarize revenue, or feed the spill range into charts.
Integration with other Excel features:
- A dynamic named range
PromoOrderscan point to=N2#so that charts or Data Validation lists update automatically. - Use the LET function to store the start and end positions once, improving readability and performance:
=LET(
StartRow, MATCH(K2,Sales[Stage],0),
EndRow, MATCH(L2,Sales[Stage],0),
FILTER(Sales, (SEQUENCE(ROWS(Sales))>StartRow)*(SEQUENCE(ROWS(Sales))<EndRow))
)
Performance considerations: On very large tables (100,000+ rows), using LET prevents MATCH from recalculating twice. Also, consider converting formulas to Values when the promo period closes to freeze historical reports.
Example 3: Advanced Technique
Scenario: A project plan lists tasks in [A2:D5000] with a \"Phase\" column in [B]. Each time the phase changes, there is a marker row. Management wants a macro-free template where selecting any two phase names from dropdowns dynamically shows the tasks between them, inclusive of the selected phases themselves, across all four columns, and ignoring blank rows.
Advanced requirements:
- The markers might not be unique. Users choose which occurrence (first, second, third) they want.
- Must work in Excel 2010 through Excel 365.
- Needs graceful error messages when inputs are invalid.
Steps:
- Two dropdowns:
- [G2] contains a list of phase names.
- [H2] contains a list of phase names.
- [I2] numeric dropdown for occurrence number (1-n).
- Define three named formulas (Formulas > Name Manager) for compatibility across versions:
StartPos
=SMALL(IF(PhaseColumn=Sheet1!$G$2,ROW(PhaseColumn)),Sheet1!$I$2)
EndPos
=SMALL(IF(PhaseColumn=Sheet1!$H$2,ROW(PhaseColumn)),Sheet1!$I$2)
Enter both with Ctrl+Shift+Enter in pre-365 Excel. They return the row numbers of the chosen occurrences.
- Named range
TasksBetween:
=IFERROR(INDEX(TaskTable, StartPos):INDEX(TaskTable, EndPos),"Invalid markers")
Because INDEX:INDEX notation returns a contiguous range, worksheets, charts, advanced filters, or SUMPRODUCT can consume TasksBetween. In Microsoft 365, you could instead spill the records:
=LET(s,StartPos,e,EndPos,
IFERROR(TAKE(DROP(TaskTable,s-1),e-s+1),"Invalid markers"))
Error handling: IFERROR returns a friendly message if the requested occurrence does not exist or if EndPos is above StartPos.
Professional tips:
- Use structured references for
PhaseColumnandTaskTableto avoid hard-coding row limits. - Wrap the formulas in N() or comment them to document the logic for future maintainers.
Tips and Best Practices
- Prefer Tables and Structured References – They auto-expand as you add rows, keeping your dynamic ranges truly dynamic without editing formulas.
- Store MATCH Results Once – In large datasets, calculate the start and end positions in LET variables or helper cells to avoid redundant recalculation.
- Document Inclusive vs Exclusive – Add comments or cell notes explaining whether the markers themselves appear in the output to prevent misinterpretation.
- Validate Marker Existence – Use COUNTIF or simple conditional formatting to alert users if either marker is missing, preventing confusing blanks.
- Leverage Named Ranges – Give the finished dynamic range a descriptive name so you can reference it in multiple formulas, charts, or pivot tables without repetition.
- Use Spill Range References – In Microsoft 365, refer to the spill with the hash symbol (e.g., G2#) to feed other formulas or charts and maintain automatic sizing.
Common Mistakes to Avoid
- Markers with Extra Spaces – Trailing spaces in source data cause MATCH to fail. Apply TRIM or clean the data first.
- Reversed Marker Order – If the end marker appears before the start marker, comparisons like greater than or less than produce no matches. Build a check: IF(StartRow≥EndRow,\"Check markers\",Formula).
- Duplicate Markers Without Clarification – Using MATCH when markers appear multiple times can return the wrong segment. Decide whether you need the first, last, or nth occurrence and use XMATCH or SMALL accordingly.
- Volatile Functions in Massive Sheets – OFFSET is volatile; on large datasets it recalculates every workbook change, slowing performance. Prefer INDEX:INDEX or FILTER where possible.
- Feeding Spill Ranges into Legacy Features – Some pre-365 features do not yet accept spill ranges. Either wrap them in AGGREGATE or convert to a static range before sharing with users on older versions.
Alternative Methods
| Method | Excel Version Compatibility | Pros | Cons | Best Use Case |
|---|---|---|---|---|
| FILTER + SEQUENCE + MATCH | 365 / 2021 | Fast, spills automatically, easy to read | Not available in older versions | Dashboards in modern Excel |
| LET with TAKE & DROP | 365 / 2021 | Very readable, calculates positions once | Same limitation as above | Complex nested reports |
| INDEX:INDEX with MATCH | All versions | Non-volatile, works in charts & pivots | Slightly harder to write, no spill output | Backward-compatible templates |
| OFFSET + MATCH | All versions | Short syntax, returns range | Volatile, slower in large sheets | Small or medium datasets |
| VBA Function | Any | Unlimited flexibility, can handle non-contiguous segments | Requires macros to be enabled, maintenance overhead | Highly bespoke reporting tools |
When migrating, start with INDEX:INDEX for universal support. Upgrade to FILTER once every stakeholder is on Microsoft 365 to unlock better readability and performance.
FAQ
When should I use this approach?
Use dynamic “between markers” logic whenever your source data grows regularly and manual filters slow you down — logs, transactional exports, or time-series readings where events are marked by keywords.
Can this work across multiple sheets?
Yes. Qualify ranges with sheet names, e.g., Sheet1!Data. If your start marker is on another sheet, reference it directly: MATCH(A1,OtherSheet!Data,0). The resulting dynamic range can even span sheets, though FILTER must be entered on the sheet where you want the spill output to appear.
What are the limitations?
FILTER cannot produce a non-contiguous range; if your markers appear multiple times and you want every segment, you’ll need a more advanced formula or VBA. Older Excel versions lack dynamic arrays, so you must depend on INDEX:INDEX or OFFSET, which do not visually spill.
How do I handle errors?
Wrap your master formula in IFERROR or use the [if_empty] argument of FILTER: FILTER(range,condition,"No records"). For development, add helper cells that show the start and end positions so you can immediately see whether markers were found.
Does this work in older Excel versions?
Yes — the INDEX:INDEX method works all the way back to Excel 2003. Just remember any array components require Ctrl+Shift+Enter in pre-365 environments. FILTER, SEQUENCE, TAKE, and DROP require Microsoft 365 or Excel 2021.
What about performance with large datasets?
In tests with 250 k rows, LET + FILTER recalculates in under a second on modern hardware. INDEX:INDEX performs similarly because MATCH executes only twice. OFFSET slows dramatically as it is volatile. Always avoid volatile functions in worksheets that recalculate frequently.
Conclusion
Mastering the technique of dynamically isolating the range between two matches unlocks an elegant way to slice your data without macros, helper columns, or manual filters. Whether you build the formula with modern FILTER or the timeless INDEX:INDEX pattern, the skill transfers directly to countless reporting, analysis, and cleanup tasks. Add this tool to your Excel arsenal, experiment with inclusive and exclusive variants, and soon you’ll automate segments of data that used to take minutes into split-second, self-maintaining flows. Keep exploring other dynamic array functions to push your efficiency even further.
Related Articles
How to Show the 10 Most Common Text Values in Excel
Learn multiple Excel methods to list the 10 most frequent text values—complete with step-by-step examples, business use cases, and expert tips.
How to Abbreviate Names Or Words in Excel
Learn multiple Excel methods to abbreviate names or words with step-by-step examples and practical applications.
How to Abbreviate State Names in Excel
Learn multiple Excel methods to abbreviate state names with step-by-step examples, professional tips, and real-world applications.