Excel 2013 Macro Code: Merge or UnMerge Cells

From SolverBase.com
Jump to: navigation, search

Problem

  • How to merge or unmerge Excel cells by using VBA macro code?
  • What is the macro code / VBA code to merge or unmerge Excel cells?


Solution

For Example you want to merge cells from E1 to E5.

  • Paste below Code in the VBA code window.


Sub Example()

    Range("E1:E5").Merge   
      
End Sub


For Example you want to unmerge cells from E1 to E5.

  • Paste below Code in the VBA code window.
Sub Example()

    Range("E1:E5").UnMerge
      
End Sub


If you don't know how to open VBA code window then use the following link...

Excel 2013 Create Macro by Using Microsoft Visual Basic Editor


  • To run the macro from the code window, press F5 or use the Start Macro Icon Start Macro Icon on the ribbon.


Start Macro icon