Export (0) Print
Expand All
1 out of 2 rated this helpful - Rate this topic

Merge Method

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

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.