MergeArea Property

Microsoft Office Web Components Visual Basic

Returns a Range object that represents the merged range containing any part of the specified range. The specified range can contain more than one cell; if the range does not contain any merged cells, it is returned unchanged. Read-only.

expression.MergeArea

expression    Required. An expression that returns a Range object.

Example

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

Sub Merge_Cells()
    Dim ssConstants
    Dim shtCurrent
    
    Set ssConstants = Spreadsheet1.Constants
    Set shtCurrent = Spreadsheet1.Worksheets("Sheet1")
    
    ' Merge cells B2:C5.
    shtCurrent.Range("B2:C5").Merge
    
    ' Set the border color of the merged cell.
    shtCurrent.Range("B2").MergeArea.Borders.Color = "Red"
    
    ' Set the border weight of the merged cell.
    shtCurrent.Range("B2").MergeArea.Borders.Weight = ssConstants.owcLineWeightThick
End Sub