Excel VBA: Unmerge Every Cell on a Sheet
In this article
You can unmerge every merged cell on a worksheet with a single VBA line: ActiveSheet.Cells.UnMerge. That unmerges all merged ranges on the active sheet at once, leaving the value in the top-left cell of each former merged area and blanking the rest. If you want to keep the text in every cell of each former merged block, you need a small loop that copies the top-left value across the range before unmerging. Both approaches are shown below, along with the errors that trip people up.
What You'll Need
- Microsoft Excel on Windows or Mac with the Developer tab enabled (File > Options > Customize Ribbon > tick Developer, or Excel > Preferences > Ribbon & Toolbar on Mac).
- A workbook saved as .xlsm (macro-enabled) if you want to keep the code, or a temporary workbook if you only need a one-off fix.
- A backup copy of the file before running anything that changes formatting across a whole sheet.
Step-by-Step
- Save a copy first. Unmerging is easy to reverse with Ctrl+Z immediately after, but once you save and close, the merge formatting is gone. Keep an untouched copy so you can compare.
- Open the workbook that contains the merged cells and click the tab of the sheet you want to clean. VBA acts on the active sheet unless you name a sheet explicitly.
- Press Alt+F11 (Windows) or Fn+Option+F11 (Mac) to open the Visual Basic Editor. Menu labels can differ slightly by Excel version and platform.
- Insert a module: in the VBE choose Insert > Module. A blank code window appears in the right pane.
- Paste the simplest version into the module:
This unmerges every merged range on the active sheet in one pass. The value that was displayed stays in the top-left cell of each former merged block; the other cells in the block are empty.Sub UnmergeSheet() ActiveSheet.Cells.UnMerge End Sub - Run it by placing the cursor inside the subroutine and pressing F5, or switch back to Excel and use Developer > Macros, select UnmergeSheet, and click Run.
- Check the result. Scroll the sheet and confirm no merged areas remain. If some cells still look merged, they may be on a different sheet, inside a protected area, or part of a table with merged header cells that Excel refuses to split while the table is active.
- Use the value-preserving version if you need the text repeated in every cell of each former merged block. This is the version most people actually want when cleaning imported reports:
This walks the used range, finds each merged area once, unmerges it, and writes the original top-left value into every cell of that area. It is slower on very large sheets but reliable.Sub UnmergeAndFill() Dim rng As Range, c As Range For Each c In ActiveSheet.UsedRange If c.MergeCells Then Set rng = c.MergeArea rng.UnMerge rng.Value = c.Value End If Next c End Sub - Save the workbook as .xlsm if you want to keep the macro. A plain .xlsx will prompt you to save without macros and discard the code.
- Run it across several sheets if needed. Replace
ActiveSheetwith a loop overThisWorkbook.Worksheets, or call the macro once per sheet tab. Avoid running it on sheets that contain charts or shapes anchored to merged cells without checking them afterwards.
Common Mistakes
- Expecting values to spread automatically. The one-line
UnMergekeeps only the top-left value. If a merged header read "Q1 Sales" across four columns, only the first column keeps the text after unmerging. - Running it on the wrong sheet.
ActiveSheetmeans whatever tab is visible in Excel when the macro runs, not the sheet you were looking at in the VBE. Click the correct tab first. - Forgetting protected sheets. If sheet protection is on, unmerging fails silently or throws an error. Unprotect the sheet first (Review > Unprotect Sheet) if you have the password.
- Losing merged formatting in tables. Excel does not allow merged cells inside a formal Excel Table (ListObject). If the sheet uses tables, convert the table to a normal range first (Table Design > Convert to Range), then unmerge.
- Not handling errors. A merged range that spans a protected area or an array formula can raise run-time error 1004. Wrap the call in
On Error Resume Nextonly if you accept that some merges may remain, and check afterwards.
Tips
- Test on a copy. Unmerging a heavily formatted report can shift column widths and row heights visually, even though the data is intact.
- If you only want to fix a selection rather than the whole sheet, use
Selection.UnMergeafter highlighting the range. - To find merged cells before unmerging, use Home > Find & Select > Go To Special > Merged cells. That highlights them so you can inspect what will change.
- Combine the unmerge with a fill-down step if you want values repeated but only within contiguous blocks, rather than the whole used range.
- Keep the macro in your Personal Macro Workbook if you clean imported files often, so it is available in every workbook you open.
Troubleshooting
- Nothing happens when you run it. Confirm macros are enabled (File > Options > Trust Center > Macro Settings) and that the sheet actually contains merged cells. Use Go To Special > Merged cells to verify.
- Run-time error 1004. Usually a protected sheet, a protected workbook structure, or merged cells inside a table. Unprotect, convert the table to a range, and retry.
- Some merges remain. They may be on hidden rows or columns, or on a different sheet. Unhide rows and columns, then rerun. If the sheet has grouped outline levels, expand them first.
- Values disappeared. That is the expected behaviour of the one-line version: only the top-left value survives. Restore from your backup and use the value-preserving macro instead.
- Excel is slow or unresponsive. The loop version walks every used cell, which can be slow on sheets with tens of thousands of rows. Turn off screen updating at the start (
Application.ScreenUpdating = False) and turn it back on at the end. - Macro will not save. You are likely saving as .xlsx. Use File > Save As and choose Excel Macro-Enabled Workbook (.xlsm).
Frequently Asked Questions
Does unmerging delete data?
No. Unmerging keeps the value in the top-left cell of each former merged area and clears the rest. If you need the value in every cell, use the value-preserving macro shown above.
Can I unmerge the whole workbook at once?
Yes. Loop over ThisWorkbook.Worksheets and call ws.Cells.UnMerge for each sheet. Check each sheet for protection first, or the loop will stop on the first protected tab.
Will this work on Excel for Mac?
Yes. The VBA object model is the same; only the shortcut to open the editor differs (Fn+Option+F11 on most Mac layouts). Menu names can vary slightly by version.
Can I undo an unmerge?
Yes, immediately after running the macro with Ctrl+Z, as long as you have not saved or closed the workbook. Once saved, the merge formatting is gone and you would need your backup.
Why does Excel refuse to unmerge some cells?
Usually because the sheet is protected, the cells sit inside an Excel Table, or the range is part of an array formula. Unprotect the sheet, convert the table to a range, or clear the array formula first.
Is there a built-in command to unmerge an entire sheet?
Not as a single menu item. You can select all cells with Ctrl+A and click Merge & Center on the Home tab to toggle merging off, but that only affects the selection and can behave oddly with tables. The VBA one-liner is faster and more predictable.