Excel VBA Unmerge: Step-by-Step Guide
In this article
To unmerge cells in Excel VBA, use the UnMerge method on a Range object. For example, Range("A1:C3").UnMerge splits every merged area in that range back into individual cells. The value from the top-left cell of each merged area is kept in that top-left cell; the other cells become empty. This works in any modern Excel version on Windows or Mac. The steps below show how to run it safely, loop through a whole sheet, and avoid the common traps.
What You'll Need
- Excel for Windows or Mac (any version that supports VBA; the Developer tab must be enabled).
- A workbook saved as
.xlsm(macro-enabled) if you want to keep the code. - Basic familiarity with the VBA Editor (Alt+F11 on Windows, or the Developer tab > Visual Basic).
- A backup copy of the workbook before running any macro that changes formatting.
Step-by-Step
- Make a backup. Save a copy of the workbook (File > Save As) before you change anything. Unmerging is not reversible with Undo after a macro runs, so the backup is your safety net.
- Open the VBA Editor. Press Alt+F11 (Windows) or go to Developer > Visual Basic (Mac: Developer > Editor). If the Developer tab is hidden, enable it via File > Options > Customize Ribbon and tick Developer.
- Insert a module. In the VBA Editor, right-click your workbook name in the Project pane and choose Insert > Module. This is where your code will live.
- Write the simplest unmerge statement. Type the following into the module:
This unmerges whatever is currently selected in Excel. It is the quickest way to test the method.Sub UnmergeSelection() Selection.UnMerge End Sub - Run it on a test range. Close the editor, select a small merged block on a scratch sheet, then press Alt+F8, choose
UnmergeSelection, and click Run. Confirm the cells split and the top-left value remains. - Unmerge a specific range without selecting it. Replace
Selectionwith an explicit range, for example:
This is safer for repeatable tasks because it does not depend on what the user has selected.Sub UnmergeSpecific() Worksheets("Sheet1").Range("A1:D10").UnMerge End Sub - Unmerge every merged cell on a worksheet. Use this loop:
Sub UnmergeAllOnSheet() Dim c As Range For Each c In ActiveSheet.UsedRange If c.MergeCells Then c.UnMerge Next c End SubMergeCellsreturns True for every cell inside a merged area, so the loop catches all of them. RunningUnMergeon an already-unmerged cell is harmless, so the check is optional but makes the intent clear. - Preserve the values if you need them. Unmerging keeps only the top-left value. If the merged cell held a label you want repeated across the split cells, fill them first. For example, after unmerging, copy the top-left value down or across with a loop, or use
Range("A1").Copy Destination:=Range("A1:A10")before unmerging if the layout allows it. - Save and test on a copy. Save the workbook as
.xlsm, then run the macro on a duplicate sheet and compare against the original. Check that no formulas referencing the merged range now return errors.
Common Mistakes
- Expecting all values to survive. Only the top-left cell of each merged area keeps its content. Everything else is discarded, and there is no Undo after a macro run.
- Running on the wrong sheet.
ActiveSheetandSelectiondepend on where the cursor is. Use explicit worksheet and range references in production code. - Forgetting that
MergeCellsis True for every cell in the area. A naive loop may callUnMergemany times per merged block; it still works, but it is slower on large sheets. - Unmerging cells that formulas depend on. A formula like
=A1pointing at a merged range can change meaning once the cells split. Check formulas before and after. - Leaving the workbook as
.xlsx. Macros are stripped from standard workbooks. Save as.xlsmor the code disappears on close.
Tips
- Turn off screen updating for large sheets:
Application.ScreenUpdating = Falseat the start andTrueat the end. This makes loops much faster. - To find merged cells before unmerging, use
Range("A1:Z100").MergeCellsto check if any exist, or loop withIf c.MergeCells Then Debug.Print c.Addressto list them. - If you only want to unmerge across rows or columns, Excel's
MergeCellsproperty does not distinguish; you must unmerge the whole area and re-merge the parts you want to keep. - Record a macro (Developer > Record Macro) while unmerging manually to see the exact code Excel generates for your version; labels and generated code can differ slightly by version and platform.
- Keep a helper routine that unmerges and then fills the former merged area with the top-left value, since that is what most reports actually need.
Troubleshooting
- "Method 'UnMerge' of object 'Range' failed." This usually means the sheet is protected. Unprotect it first (Review > Unprotect Sheet) or unprotect in code with the correct password.
- Nothing happens. Check that the range actually contains merged cells. Select it and look at Home > Merge & Center; if the button is not highlighted, there is nothing to unmerge.
- Values disappeared. That is expected: only the top-left value is kept. Restore from your backup and fill the values before unmerging.
- Macro not listed in Alt+F8. The code may be in a sheet module rather than a standard module, or macros may be disabled. Check File > Options > Trust Center > Macro Settings.
- Formulas show #REF! or wrong results. Unmerging changed the cell layout. Review dependent formulas and adjust references, or restore the backup and unmerge a smaller range.
Frequently Asked Questions
Does UnMerge keep the data?
Only the value in the top-left cell of each merged area is kept. All other cells in the merged area become empty, and there is no built-in Undo after a macro runs.
Can I unmerge all cells on a sheet at once?
Yes. Loop through ActiveSheet.UsedRange and call UnMerge on any cell where MergeCells is True, as shown in the steps above.
Does UnMerge work on protected sheets?
No. You must unprotect the sheet first, either manually via Review > Unprotect Sheet or in code with ActiveSheet.Unprotect "password".
Will unmerging break my formulas?
It can. Formulas that reference the merged range may change meaning once the cells split. Check dependent formulas before and after, and keep a backup.
Is there a way to unmerge without VBA?
Yes. Select the range and click Home > Merge & Center to toggle merging off. VBA is only needed for bulk or repeatable operations.
Does the code work on Excel for Mac?
Yes, the UnMerge method and standard module code work in Excel for Mac. Menu labels and shortcut keys differ slightly, but the VBA syntax is the same.