How to Use COUNTIF or COUNTIFS in Merged Cells in Google Sheets (Without Unmerging)

Published on

Merged cells often make spreadsheets look cleaner, but they break many formulas — especially COUNTIF and COUNTIFS. If you’re trying to count based on values in merged cells, you’ll likely get incorrect results… unless you know this workaround.

In this tutorial, I’ll show you how to correctly use COUNTIF and COUNTIFS in merged cells in Google Sheets without unmerging them, using a clever LOOKUP trick.

Why COUNTIF Fails with Merged Cells

Let’s say you merge cells A1:A10 and enter a date. Only A1 actually contains the value; the rest are blank. So a formula like:

=COUNTIF(A1:A10, "2024-08-15")

will only count one cell, even if the entire merged range visually appears to contain the date. This behavior causes misleading counts in datasets that use merged cells for grouping.

The Fix: Use LOOKUP to Fill Merged Cell Values Virtually

We can virtually “fill down” merged values into each row using this formula:

=ARRAYFORMULA(LOOKUP(ROW(A3:A14), IF(LEN(A3:A14), ROW(A3:A14)), A3:A14))

What it does:

  • ROW(A3:A14) creates a list of row numbers.
  • IF(LEN(A3:A14), ROW(A3:A14)) marks only non-empty cells.
  • LOOKUP(...) fills down the last seen non-empty value — simulating an unmerged range.

This virtual range can then be safely used with COUNTIF.

Correct COUNTIF for Merged Cells

Scenario:

You have dates in merged cells in column A and want to count how many consignments were dispatched on a specific date (in F3).

COUNTIF formula with merged cells in Google Sheets

Incorrect (Standard) Formula:

=COUNTIF(A3:A14, F3)

Correct Formula with LOOKUP:

=COUNTIF(
  ARRAYFORMULA(LOOKUP(ROW(A3:A14), IF(LEN(A3:A14), ROW(A3:A14)), A3:A14)),
  F3
)

This version accounts for merged cells and gives you the correct count.

Important: To get an accurate count, ensure there are no empty cells in the COUNTIF range—except for those created by merged cells. If it’s difficult to remove empty cells, consider entering a placeholder like “-” or “x” to exclude them from the count. You can do this easily by applying Data > Create a filter to the column and filtering for blanks. Also, use closed-ended ranges (e.g., A3:A14 instead of A3:A) to avoid counting unintended values outside your dataset.

Using COUNTIFS with Merged Cells (Multiple Conditions)

Now let’s say you also want to count only if the person’s name in column B matches a specific value in G3.

COUNTIFS formula applied to merged cells in Google Sheets

Correct Formula with Multiple LOOKUPs:

=COUNTIFS(
  ARRAYFORMULA(LOOKUP(ROW(A3:A14), IF(LEN(A3:A14), ROW(A3:A14)), A3:A14)),
  F3,
  ARRAYFORMULA(LOOKUP(ROW(B3:B14), IF(LEN(B3:B14), ROW(B3:B14)), B3:B14)),
  G3
)

Example Output:

If F3 = 2021-08-15 and G3 = "Nicole", the formula will correctly return the number of consignments she dispatched on that date — even though the original data contains merged cells.

Bonus Tip: Hardcoding Criteria

Instead of using cell references like F3 and G3, you can hardcode the criteria:

=COUNTIFS(
  ARRAYFORMULA(LOOKUP(ROW(A3:A14), IF(LEN(A3:A14), ROW(A3:A14)), A3:A14)),
  DATE(2021, 8, 15),
  ARRAYFORMULA(LOOKUP(ROW(B3:B14), IF(LEN(B3:B14), ROW(B3:B14)), B3:B14)),
  "Nicole"
)

Summary: How to Handle Merged Cells with COUNTIF(S)

ProblemSolution
COUNTIF/COUNTIFS fail on merged rangesUse LOOKUP to simulate unmerged values
Need to count based on a merged columnWrap the column in ARRAYFORMULA(LOOKUP(…))
Using multiple criteriaApply the LOOKUP trick to all criteria ranges
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

More like this

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

1 COMMENT

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.