NamedRange.MergeCells Property (2007 System)

Gets or sets a value that indicates whether the NamedRange control contains merged cells.

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

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public Property MergeCells As Object
'Usage
Dim instance As NamedRange 
Dim value As Object 

value = instance.MergeCells

instance.MergeCells = value
[BrowsableAttribute(false)]
public Object MergeCells { get; set; }
[BrowsableAttribute(false)]
public:
property Object^ MergeCells {
    Object^ get ();
    void set (Object^ value);
}
public function get MergeCells () : Object 
public function set MergeCells (value : Object)

Property Value

Type: System.Object
true if the NamedRange control contains merged cells; otherwise, false.

Examples

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 Sub MergeRange()
    Dim namedRange1 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1", "A5"), _
        "namedRange1")

    Dim namedRange2 As Microsoft.Office.Tools.Excel.NamedRange _
        = Me.Controls.AddNamedRange(Me.Range("A1"), "namedRange2")

    Dim beforeMergeAddress As String = _
        namedRange2.MergeArea.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)

    Dim afterMergeAddress As String = _
        namedRange2.MergeArea.Address(, , _
        Excel.XlReferenceStyle.xlA1, , )

    MessageBox.Show("After merging, the MergeArea property is '" & _
        afterMergeAddress & "' and the MergeCells property is " & _
        " '" & namedRange2.MergeCells.ToString() & "'.")
End Sub
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", missing],
        "namedRange2");

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

    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(
        missing, missing, Excel.XlReferenceStyle.xlA1, missing, missing);

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

.NET Framework Security

See Also

Reference

NamedRange Class

NamedRange Members

Microsoft.Office.Tools.Excel Namespace