Merge UnMerge Cell Range in Excel VBA

Home/Excel VBA/Merge UnMerge Cell Range in Excel VBA

Description:

You can Merge UnMerge Cell Range in Excel VBA, it is required if you want to make bigger cells, instead of existing cell to fit your data and needs.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


Merge UnMerge Range in Excel VBA – Solution:

Merge UnMerge Cell Range in Excel VBA We can use Merge and UnMerge methods of a Range to Merge UnMerge Cell Range in Excel VBA.

Merge UnMerge Cell Range in Excel VBA – Example:

Following is the example to show you how to merge or UnMerge the cells in excel using VBA.

Code to merge Cells
Sub sbMergeRange()
Range("A1:B3").Merge
End Sub
Code to unmerge Cells
Sub sbUnMergeRange()
Range("A1:B3").UnMerge
End Sub
Instructions:
  1. Open an excel workbook
  2. Press Alt+F11 to open VBA Editor
  3. Insert a Module for Insert Menu
  4. Copy the above code and Paste in the code window
  5. Save the file as macro enabled workbook
  6. Press F5 to execute it
LIMITED TIME OFFER
By |July 7th, 2013|Excel VBA|4 Comments

About the Author:

Excel VBA Developer having around 8 years of experience in using Excel and VBA for automating the daily tasks, reports generation and dashboards preparation. Valli is sharing to helps us automating daily tasks.

4 Comments

  1. ali September 21, 2015 at 6:55 PM - Reply

    but i want to merge cells in two for loops based on i and j.
    for example,
    I want to merge (i,j) and (i,j+1)
    how is syntax here?

    • Cass January 22, 2016 at 9:18 PM - Reply

      You can dynamically reference cells using cells inside the range.
      My code usually looks like this:
      Range(Cells(row #, column #), Cells(Last row, Last column)

      Hope that helps.

  2. sam February 8, 2016 at 8:38 PM - Reply

    Cass, Thanks for the reply. Can you go one step further and show how to initiate a right, left or center justification of the merge.

    Thanks,
    Sam

  3. Janu September 9, 2016 at 12:21 PM - Reply

    hi,

    i want to merge a particular rowcells with referring the merged cells in any column of that particular row kindly just the coding for that
    Regards,
    Janu

Leave A Comment


Related pages


iferror function excel 2010vba msgbox custom buttonsconvert excel file to xmlexcel vba program examplescombine excel worksheets into one worksheetactivex controllerhow do you create a macro in excelworksheet function in vbadaily standup meeting templatejob costing template excelexcel macros password removerfree excel userform templatesremove duplicates in arrayexcel vlookup formulas with examplesvba macro programmingdelete duplicate entries excelinsert checkbox in excel 2003vlookup in excel examplevba save workbooklooping in excelweekly report template pptexcel vba select cellshow to count columns in excelexcel adding rows formulabasic macro excelhow to unhide all columnsexcel chart column widthunprotecting excel workbook without passwordunlock excel without passwordsum function vbavba in excel tutorialexcel vba cell valuebeginner excelfind duplicate rows excelhow to sort in ascending order in excellocate duplicates in excelmultiple ifs in excelcountif function on excelexcel 2007 macros tutorialexcel multiple if conditionsexcel vba templatesort excel column alphabeticallymsgbox promptdistinct rows in exceljob costing excel templateexel sumifadding checkbox in excelbasic vlookup exampletrim function in excel 2010advanced excel exerciseshow to unlock cells in excelsql query tutorial for beginnerscost reduction template excelexcel chart gridlinesunhide hidden columns in excelloop macro excelmicrosoft office gantt chart templatecombining if statements in excelvba loopingcsv converter to excelhow to remove unwanted rows in excelmeeting template excelhow to activate activex controllength of array vbavba string containsvba programming for excelexcel sumif formulauses of macro in exceluser forms in excelpivot tables explainedunprotect all sheets vbaremoving empty rows in excelhow to merge to rows in excelhow to protect excel sheet 2007demographic pie chartexcel formula row heightexcel vba message box yes noisna vlookupmacros in excel examplessales dashboard excelhow to delete header in excelkpi dashboard examples excelvba message box multiple lines