NamedRange.Merge Method (Object)


Creates a merged cell from the NamedRange control.

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

void Merge(
	object Across


Type: System.Object

true to merge cells in each row of the specified range as separate merged cells. The default value is false.

The value of a merged range is specified in the cell in the upper-left corner of the NamedRange control.

For information on optional parameters, see Optional Parameters in Office Solutions.

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"],

    Microsoft.Office.Tools.Excel.NamedRange namedRange2 =

    string beforeMergeAddress = namedRange2.MergeArea.get_Address(

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


    string afterMergeAddress = namedRange2.MergeArea.get_Address(

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