Expand Minimize

NamedRange.MergeArea Property

Gets a Microsoft.Office.Interop.Excel.Range that represents the merged range containing the NamedRange control.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)

Range MergeArea { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.Range
A Microsoft.Office.Interop.Excel.Range that represents the merged range containing the NamedRange control. If the NamedRange control is not in a merged range, this property returns a Microsoft.Office.Interop.Excel.Range that represents the NamedRange control.

The MergeArea property only works on a single-cell range.

The following code example displays the value of the MergeArea and MergeCells properties of a single-cell NamedRange before and after using the Merge method to merge a multiple-cell NamedRange that contains the single-cell NamedRange.

This example is for a document-level customization.

private void MergeRange()
{
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    Microsoft.Office.Tools.Excel.NamedRange namedRange2 =
        this.Controls.AddNamedRange(this.Range["A1"],
        "namedRange2");

    string beforeMergeAddress = namedRange2.MergeArea.get_Address(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show("Before merging, the MergeArea property is '" +
        beforeMergeAddress + "' and the MergeCells property is " +
        " '" + namedRange2.MergeCells.ToString() + "'.");

    namedRange1.Select();
    namedRange1.Merge(false);

    string afterMergeAddress = namedRange2.MergeArea.get_Address(
        Excel.XlReferenceStyle.xlA1);

    MessageBox.Show("After merging, the MergeArea property is '" +
        afterMergeAddress + "' and the MergeCells property is " +
        " '" + namedRange2.MergeCells.ToString() + "'.");
}

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft