Dynamic Merged Cells in Excel

Mynda Treacy

July 1, 2025

At first glance, (regular) merged cells can make your spreadsheet look clean and polished - just the way most teams like it. But beneath that tidy surface, they wreak havoc on your ability to filter, sort, analyse, and summarize data.

why you shouldn't merge cells in Excel?

In this guide, I’ll show you why merged cells break Excel functionality - and exactly how to create dynamic merged cells in Excel without compromising on readability or layout.

Watch the Dynamic Merged Cells Video

Subscribe YouTube

Get the Dynamic Merged Cells Practice File

Enter your email address below to download the free file.



By submitting your email address you agree that we can email you our Excel newsletter.

Why Merged Cells Are a Problem for Filters & PivotTables

Let’s say you’ve got a table with merged cells in the “Department” and “Expense Type” columns. It looks great—until you try to:

  • Filter the data: Filtering by a column like “Department” for the HR transactions won’t return all matching results because merged cells break row alignment:
merged cells in Excel prevents filtering
  • Build PivotTables: Only the first row of each group retains the department name; the rest are counted as blanks:
merged cells break pivottables in Excel
  • Sort your data: Sorting is a non-starter with Excel refusing to play nice when merged cells aren’t the same size:
merged cells in Excel prevents sorting
  • Use formulas: Referencing merged cells in formulas becomes unreliable and painful.

Bottom line: Merged cells might look good, but they break Excel’s core features.

The Better Way: Dynamic Merged Cells = Clean Layout + Full Functionality

Step 1: Unmerge the Problem Cells

  • Select the “Department” and “Expense Type” columns.
  • Go to Home > click Merge & Center to unmerge them.
how to unmerge cells in Excel?

Step 2: Fill the Empty Cells

To restore the data structure:

1. Select the columns again.

2. Press Ctrl+G > Special > choose Blanks.

how to quickly fill cells in Excel?

3. With the blanks selected, type = and press the Up Arrow key.

4. Press Ctrl+Enter to apply the formula to all selected cells.

how to apply formulas to all selected cells in Excel?

5. Copy the columns, then Paste Special > Values to remove the formulas.

Now every cell contains the correct label, and your dataset is clean and functional.

Step 3: Turn It Into a Smart Excel Table

  • Select a single cell in your dataset or the whole table and press Ctrl+T to create a table.
  • Select a clean, white style (e.g., “White Table Style Light 15”) and turn off banded rows if preferred.
how to quickly insert a table in Excel?

Tip: Excel Tables also make your data easier to manage, analyze, and reference in formulas.

Step 4: Visually Clean It Up with Conditional Formatting

Now your data works—but it’s cluttered with repeated values. Let’s hide them (visually only) using Conditional Formatting formulas.

Hide Repeats with a Custom Format

  1. Select the “Department” and “Expense Type” columns (excluding the headers).
  2. Go to Home > Conditional Formatting > New Rule.
  3. Choose “Use a formula to determine which cells to format.”
  4. Enter the formula:
    =A4=A3
    (Adjust for column as needed, and use relative references by pressing F4 three times.)
  5. Click Format > Number > Custom, and enter this format code:
    ;;;
    (This hides the content but retains full functionality.)
  6. In the Borders tab, remove the Top Border so repeated values visually merge with the ones above.

This makes your table much easier to scan, without using actual merged cells.

Step 5: Fix Filtering Issues

When you filter the table, the conditional formatting still compares hidden rows, which can cause the first visible row of a group to appear blank as you can see in the screenshot below.

how to  solve the blank cell condiitional formatting issue in Excel?

Solve it with the AGGREGATE Function

With the AGGREGATE function we can check if the row above is visible:

=AGGREGATE(3,5,A3)
  • 3 counts non-empty cells.
  • 5 tells Excel to ignore hidden rows.
  • A3 refers to the cell above the current row.

Combine it with your existing rule:

=AND(A3=A2, AGGREGATE(3,5,A2))

Apply this formula in your Conditional Formatting rule to ensure that hidden rows don’t affect the visibility logic.

Now when you filter by “Pending” or any other criteria, only the appropriate values are hidden, making everything work as intended:

why use AGGREGATE in conditional formatting rules in Excel?

One Caution: Inserting or Deleting Rows

Conditional Formatting rules that reference relative rows (like A3=A2) can break when you insert or delete rows. Excel will fragment/duplicate the rule in the background.

There’s a more advanced workaround using the OFFSET function let me know in the comments if you want a full breakdown of that approach!

The Payoff: Flawless PivotTables and Clean Analysis

With your table now properly structured:

  • Insert a PivotTable via Insert > PivotTable.
  • Add Department to Rows and Amount to Values.
  • Add Status to Filters and choose “Pending”.

Now you’ve got a professional breakdown of your data that updates dynamically - without a single merged cell in sight:

how to achieve a clean dataset before creating PivotTables in Excel?

Wrap-Up: Clean Layouts Without Sacrificing Functionality

Merged cells might look neat, but they cause more problems than they solve. By unmerging, filling blanks, and using Conditional Formatting tricks, you create dynamic merged cells that keep your spreadsheet clean and functional.

Want to Take It Further?

Check out my Excel Expert Course if you want to master layouts, formulas, PivotTables, and analysis workflows.

AUTHOR Mynda Treacy Co-Founder / Owner at My Online Training Hub

CIMA qualified Accountant with over 25 years experience in roles such as Global IT Financial Controller for investment banking firms Barclays Capital and NatWest Markets.

Mynda has been awarded Microsoft MVP status every year since 2014 for her expertise and contributions to educating people about Microsoft Excel.

Mynda teaches several courses here at MOTH including Excel Expert, Excel Dashboards, Power BI, Power Query and Power Pivot.

16 thoughts on “Dynamic Merged Cells in Excel”

  1. Another common annoyance with merged cells: when someone makes centered titles and subtitles above columns of tabular data that will be pasted into presentations. Trying a CTRL-Shift-Down to select a column of cells, as soon as a row is found that’s part of a merged cell, you wind up getting a range of multiple columns selected, which is almost never what you want.
    You can fix them in 2 seconds while still keeping the visual display unchanged: First click Merge & Center to unmerge the cells; then, while the full range is still selected, immediately hit CTRL-1 to Format Cells, and change horizontal alignment to Center Across Selection.

    Reply
    • Thanks for sharing, Marvin. This is a cool hidden tip and a bonus that you can also summarise the data with a PivotTable, but sorting doesn’t work. That said, if you have your data grouped this way, then it should already be sorted.

      Reply
  2. To get around the inserting/deleting issue you could use a sheet-based relative reference range name like CellAbove in the conditional format to always refer to the cell above.

    Reply
  3. Hi Mynda, thanks a lot for this idea!
    However, I can see two potential caveats and offer my solutions to them:

    1) when there are more than two rows of the same value in a column, the bottom border lines apply and the cells don’t seem merged (only the first two rows).
    My solution was to modify the rule so it removes both top AND bottom border and to add an inverse rule (NOT(rule1)) to explicitly create the bottom line in cases wehere the value does change.

    2) In my context, the logic of the rule should reflect the hierarchy of categories so, when for example I have a line name=John and instrument=guitar and the following line has name=George, instrument=guitar, then I do not want the two guitars to merge (across players). Therefore, assuming the category columns are in a hierarchical order from left (col A) to right, I used this formula to determine, when there is a change in any of the (super)categories down to the current column.
    =CONCAT(OFFSET($A2,,,(COLUMN(A2)-COLUMN($A2)+1))) = 
    CONCAT(OFFSET($A2,-1,,,(COLUMN(A2)-COLUMN($A2)+1)))

    Since evaluating formulas can not handle arrays the way cell formulas do, I had to use the concatenation.
    Summed up, that is a plenty of Offset formulas resulting in a considerable computing load, but it is worth the result. Perhaps anybody has a more effective solution?

    Reply
    • Hi Vaclav,

      I hadn’t noticed this issue. Interesting solution, but I couldn’t get it to work. However, this formula can replace the AND formula to handle where the ‘Pending’ status may not occupy consecutive rows:

      =SUMPRODUCT((A$4:A4=A4)*(SUBTOTAL(103,OFFSET($A$4,ROW($A$4:$A4)-ROW($A$4),0))))<>1

      Mynda

      Reply
  4. Thank you Mynda.
    Totally agree about merged cells – IMHO they are more trouble than they’re worth, so I avoid them.
    Conditional formatting is a clever way of hiding unnecessary duplicates.
    Is the “;;;” better than making the font colour white (assuming the background is white?
    It would be interesting and useful to see the OFFSET solution. While data often simply gets added to the bottom of the table, inserting and deleting rows (and the influence this has on conditional formatting rules) is something one often encounters.

    Reply
    • The ;;; isn’t necessarily better than the font colour method in terms of calc efficiency, but it avoids accidently revealing the text if someone adds a cell fill colour. Noted about OFFSET

      Reply

Leave a Comment

Current ye@r *