Sequence Numbering in Merged Cells in Google Sheets

To autofill sequence numbering in merged cells in a column, we can use an array formula in Google Sheets.

For example, I have names in B2:B, and some rows are merged based on the formatting.

Accordingly, I have merged cells in A2:A to match the rows in B2:B.

Now, how do we autofill serial numbers in the merged cells in column A corresponding to the names in column B?

Let’s find out.

Array formula for sequence numbering in merged cells

Array Formula for Sequence Numbering in Merged Cells

The best solution is to use an array formula in cell A2 to achieve sequence numbering in merged cells A2:A in Google Sheets. I’ll come to that shortly.

Some users follow a non-array method, which is a bit tedious:

  • Select A2:A and unmerge the rows (Format > Merge cells > Unmerge).
  • In cell A2, enter:
    =IF(LEN(B2), COUNTA($B$2:B2), )
  • Drag the formula down until the last row you need (say, up to row #19).
  • Then, select B2:B19.
  • Right-click and select Copy.
  • Right-click on cell A2 and select Paste special > Format only.

It’s a time-consuming process.

Instead, you can use my array formula to auto-fill sequence numbers in a merged column — no need to unmerge A2:A.

Just insert the formula in cell A2, and it will automatically populate the serial numbering in the merged column based on the names in column B.

I have two formula options for you.

1. VLOOKUP to Auto Fill Sequence Numbers in Merged Cells

Array Formula #1:

=ArrayFormula(IFNA(VLOOKUP(ROW(B2:B), {FILTER(ROW(B2:B), LEN(B2:B)), SEQUENCE(COUNTA(B2:B), 1)}, 2, 0)))

Insert the above array formula in cell A2.

It will automatically fill the sequence numbers in a merged column corresponding to the values in B2:B.

Formula Explanation

To understand the VLOOKUP formula, start from the middle — the FILTER part:

FILTER(ROW(B2:B), LEN(B2:B))

This returns the row numbers where there are actual values in B2:B.

Here, LEN(B2:B) checks whether the cell is non-blank.

The output will be something like row numbers 2, 5, 6, 9, 12, and 15.

Next, the SEQUENCE part:

SEQUENCE(COUNTA(B2:B), 1)

COUNTA(B2:B) counts the non-blank cells (names) in B2:B. Suppose there are six names — the sequence would generate numbers 1 to 6.

Then, using curly brackets {}, I create a two-column array:

{FILTER(ROW(B2:B), LEN(B2:B)), SEQUENCE(COUNTA(B2:B), 1)}

The result is a two-column table — first with the row numbers and second with the sequence numbers.

VLOOKUP logic for generating serial numbers

Now, VLOOKUP searches the first column (row numbers) for ROW(B2:B) from row 2 downwards.

If it finds a match, it returns the serial number from the second column.

If no match is found, IFNA ensures it leaves the cell blank.

2. Running Count to Auto Fill Sequence Numbers in Merged Cells

Array Formula #2:

=ARRAYFORMULA(IF(LEN(B2:B), COUNTIFS(ROW(B2:B), "<="&ROW(B2:B), LEN(B2:B), ">0" ), ))

Again, just insert this formula into A2.

It will automatically generate serial numbering in merged column A2:A without the need to unmerge anything.

Formula Explanation

This formula uses COUNTIFS and follows a simple running count logic:

  • For each row, it checks if the row number is less than or equal to the current row number.
  • It also checks if there is a value in column B.

If both conditions are met, it counts how many such rows there are — giving you the sequence numbering in merged cells.

Conclusion

To achieve sequence numbering in merged cells in Google Sheets, you can try either of the above formulas.

Both work great, but depending on how many merged rows you have, one might be faster than the other.

Just insert the formula and forget about manual dragging or formatting!

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Sort Pie Slices in Google Sheets

To sort pie slices in a pie chart, you need to sort the data...

Filter Items Unique to Groups in Google Sheets

In this tutorial, we'll learn how to filter items unique to groups in Google...

Find Common Items Across Multiple Columns in Google Sheets

This tutorial explains how to find common items across multiple columns in Google Sheets....

Sort Column by Length of Text in Google Sheets

To sort a column by length of text, you can either use the QUERY...

More like this

How to Sort Pie Slices in Google Sheets

To sort pie slices in a pie chart, you need to sort the data...

Filter Items Unique to Groups in Google Sheets

In this tutorial, we'll learn how to filter items unique to groups in Google...

Find Common Items Across Multiple Columns in Google Sheets

This tutorial explains how to find common items across multiple columns in Google Sheets....

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.