Share via


NamedRange.Insert Method

Inserts a cell or a range of cells into the NamedRange control and shifts other cells away to make space.

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

Syntax

'Declaration
Function Insert ( _
    Shift As Object, _
    CopyOrigin As Object _
) As Object
Object Insert(
    Object Shift,
    Object CopyOrigin
)

Parameters

Return Value

Type: System.Object

Remarks

Optional Parameters

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

Examples

The following code example sets values in cells A1 through A3, and then uses the Insert method to insert a blank cell into a NamedRange control named NamedRange1 that is set to cell A1. This operation shifts the cells in the range down, which means that NamedRange1 is now set to cell A2. To demonstrate this, the example sets the value of NamedRange1 to Raven, which displays in cell A2.

This example is for a document-level customization.

Private Sub InsertIntoRange()
        Me.Range("A1").Value2 = "Robin" 
        Me.Range("A2").Value2 = "Sparrow" 
        Me.Range("A3").Value2 = "Crow" 

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

        namedRange1.Insert(Excel.XlInsertShiftDirection.xlShiftDown, )
        namedRange1.Value2 = "Raven" 
    End Sub
private void InsertIntoRange()
{
    this.Range["A1"].Value2 = "Robin";
    this.Range["A2"].Value2 = "Sparrow";
    this.Range["A3"].Value2 = "Crow";

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

    namedRange1.Insert(Excel.XlInsertShiftDirection.xlShiftDown);
    namedRange1.Value2 = "Raven";
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace