Merge Method

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Creates a merged cell from the specified range. When you create a merged cell, the value in the upper-left cell in the specified range is used for the merged cell value. All other cell values in the merged cell are ignored.

expression.Merge(Across)

expression   An expression that returns a Range object. This method fails if the range only partially encloses a previously merged cell.

Across  Optional Variant. True to merge cells in each row in the specified range as separate merged cells. The default value is False.

Example

This example creates a merged cell from the range B2:C5 and puts a thick red border around the merged cell.

Sub Merge_Cells()     Dim ssConstants     Dim rngMerged         Set ssConstants = Spreadsheet1.Constants         ' Merge cells B2:C5.     Spreadsheet1.ActiveSheet.Range("B2:C5").Merge         ' Set a variable to the merged range.     Set rngMerged = Spreadsheet1.ActiveSheet.Range("B2").MergeArea         ' Format the merged cell.     rngMerged.Borders.Color = "Red"     rngMerged.Borders.Weight = ssConstants.owcLineWeightThick     rngMerged.HorizontalAlignment = ssConstants.xlHAlignCenter     rngMerged.VerticalAlignment = ssConstants.xlVAlignCenter End Sub