Merge Neighbouring Rows
Merge Neighbouring Rows
A spreadsheet with a two-line header, or an entry that the source spread over two rows. The mergerows function joins a row with the rows below it, column by column, so that what belongs together ends up in one row.
What mergerows does
Give it a starting row, how many rows below it to take in, and a separator. In every column, the values of those rows are joined into the starting row, and the rows that were merged in are removed. The number of columns does not change; the rows after the group move up.
The classic case is a header written over two rows, which sorting, filtering and accessibility all handle badly. Merged with the arguments 1 (start at row 1, take in 1 more row, separator <br/> - the defaults):
| Row | Before: col 1 | col 2 | col 3 | col 4 |
|---|---|---|---|---|
| 1 | Region | Revenue | Revenue | Units |
| 2 | (empty) | 2025 | 2026 | 2026 |
| 3 | North | 1200 | 1350 | 410 |
| 4 | South | 950 | 990 | 302 |
| Region | Revenue 2025 |
Revenue 2026 |
Units 2026 |
|---|---|---|---|
| North | 1200 | 1350 | 410 |
| South | 950 | 990 | 302 |
One header row, two lines per heading, and the data now starts at row 2 - which is what sorting, pagination and filtering expect when Header Size is 1.
Setting it up
In step 5 (Modifications) of the Table Wizard, click Add new Data Modification, set Function Type to Built-in/Existing one, choose mergerows as the Function Name and type the arguments in Function Args. Leave Table Element and Element Range at Table and all.
![A Data Modification rule in step 5 of the Table Wizard with Function Name mergerows, its description, the arguments 1^1^<br/> and the argument format [startRow]^[additionalRows]^[separator].](/tabulizer7/images/tutorials/data-modifications/mergerows-function.png)
The arguments
[startRow]^[additionalRows]^[separator]
| Part | Required | Default | Meaning |
|---|---|---|---|
| startRow | Yes | - | The row the merged values go into, counting from 1. Row 1 is usually the header. |
| additionalRows | No | 1 | How many rows immediately below to merge in. 1 means two rows in total. |
| separator | No | <br/> |
The text placed between the values of each column. The default puts each value on its own line. Kept exactly as typed, spaces and HTML included. |
Examples
| Arguments | "Revenue" + "2025" becomes |
|---|---|
1 |
Revenue 2025 (two lines) |
1^1^ (a space after the last caret) |
Revenue 2025 |
1^1^ |
Revenue2025 |
1^^ - |
Revenue - 2025 (default count, your separator) |
A second use: entries spread over two rows
A timetable that put a second session for the same day on a row of its own, with the day left empty:
| Day | Session |
|---|---|
| Monday | Yoga |
| (empty) | Pilates |
| Tuesday | Swimming |
With 2, rows 2 and 3 become one row: "Monday" and "Yoga
Pilates". The empty Day cell still gets the separator, so the Day cell ends in an invisible line break - harmless in a table.
Things to know
Why did nothing happen?
The table is left as it was when the starting row or the count is not a whole number of at least 1, or when the group would run past the last row.
Can I merge several groups?
One rule merges one group. Add a rule for each group, and remember that each merge moves the rows after it up: a second rule meant for the old rows 5 and 6 must say 4 once rows 1 and 2 have become one. When two rules depend on each other like this, set their Priority so they run in the order you counted in.
Does it work on data that changes?
The row numbers are fixed, so it suits rows that are always in the same place, such as a header. Groups that move about as the data changes are better handled in the data source itself.
Is HTML in the cells kept?
Yes. Values are joined as they are, and the separator itself may be HTML.
What about merging columns?
That is mergecells, in the previous tutorial.
Try it on your own data
Open the Table Wizard, paste a table with a two-row header in step 1 and add a mergerows modification in step 5.