Create Dynamic Task Groups from a Variable-Length Range in Excel
Question details
Create flexible task groups from a worksheet where each nonblank activity number in column D begins a new task and the following rows belong to that task.

- Product
- Microsoft Excel 365
- Device & OS
- not provided
- Scenario
- The worksheet is used as the data-entry source for other tabs that populate staff paperwork and exports. Task groups must expand or shrink according to the number of entered employee rows.
- Observed behavior
- Fixed row ranges restrict each task to a predefined number of people and can create unnecessary pages when tasks contain different numbers of rows.
Confirm that every task begins with an activity number in column D and that the rows below it remain blank in column D until the next task begins. Choose a column that is populated only for valid employee records if you want to exclude unused rows from the results.
Use SCAN and FILTER to return a selected variable-length task group
Use this approach in Excel 365 when you want one spill formula to number activity groups and return all populated rows for a selected task.
SCAN increases the group number whenever it finds a nonblank cell in column D. FILTER then returns only the records whose generated group number matches the task number you select.
Place the task group number you want to export in K1, such as 1 for the first activity or 2 for the second. Adjust A2:H1000 in the formula to match the full range of columns you need to return.
On an export sheet, select the first output cell and enter: =LET(data,A2:H1000,activity,D2:D1000,groups,SCAN(0,activity,LAMBDA(g,x,g+(x<>""))),FILTER(data,(groups=K1)*(A2:A1000<>""),"No records found"))
Press Enter and allow the formula to spill. It returns every populated employee row after the selected activity number, stopping automatically when the next nonblank activity number in column D starts another group.
Replace the value in K1 with another group number. The FILTER result updates to show the rows for that activity without changing a fixed five-row or ten-row range.

Create a helper group ID column when SCAN is unavailable
Use this compatible method when your Excel version does not include the SCAN function or when you prefer to inspect each row's assigned task group.
Build Flexible Task Exports with WPS Spreadsheets
WPS Spreadsheets can organize activity-based records into flexible task groups with formulas, then filter the selected group's rows into a separate paperwork or export sheet. Use a group ID column and FILTER-based output to avoid fixed row blocks when crew sizes change.
- 1. Open the task-entry workbook: Open the Excel workbook in WPS Spreadsheets and select the sheet that contains activity numbers in column D.
- 2. Add a group ID column: In an unused column, enter =COUNTIF($D$2:D2,"<>") in the first data row and fill it down to assign each row to its current activity group.
- 3. Set the group to export: On a separate export sheet, enter the required group number in a selector cell, such as K1.
- 4. Return the matching rows: Select the output cell and use =FILTER(A2:H1000,(I2:I1000=K1)*(A2:A1000<>""),"No records found") to display the complete selected task group.

Frequently Asked Questions
How does Excel know where one task group ends?
Each nonblank activity number in column D starts a new group. The rows after it remain in that group until Excel reaches the next nonblank cell in column D.
Can I return a task group to another worksheet automatically?
Yes. Put the group number to return in a selector cell, then use FILTER on the destination sheet. For example, filter the source range by the helper Group ID column and the selected group number.
Why does my FILTER result include blank rows?
Add a condition that checks a column containing employee data, such as *(A2:A1000<>""). This excludes rows that have a group ID but do not contain a valid employee record.
What should I use if my Excel version does not have SCAN?
Use a helper Group ID column with =COUNTIF($D$2:D2,"<>") and fill it down. Then use FILTER to return rows that match the selected helper ID.
Can task groups contain more than five employees?
Yes. Because the group is determined by the next activity number in column D rather than a fixed row count, a task can contain any number of populated employee rows.




