In this post, you’ll learn how to Merge cells and Unmerge cells in Excel VBA and apply them in your Excel workbook.
Table of Contents
Merge Cells and Unmerge Cells in Excel VBA
You can use .merge and .unmerge commands to merge and unmerge cells in your spreadsheets using excel VBA . The following operations can be done using the commands.
- Merge Cells using VBA
- Unmerge Cells using VBA
- Merge Rows using VBA
- Merge Columns using VBA
Merge Cells Using VBA
To merge cells using VBA, use the Range.Merge method.
Code:
Sub MergeCells() Range("A1:D1").Merge End Sub
Unmerge Cells Using VBA
To merge cells using VBA, use the Range.UnMerge method.
Code:
Sub UnmergeCells() Range("C1").UnMerge End Sub
Merge Rows Using VBA
To merge rows using VBA,
Code:
Sub MergeRows() Range("1:5").Merge End Sub
Merge Columns Using VBA
To merge columns using VBA,
Code:
Sub MergeColumns() Range("A:C").Merge End Sub