Aracılığıyla paylaş


NamedRange.Insert(Object, Object) Method

Definition

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

public object Insert (object Shift, object CopyOrigin);
abstract member Insert : obj * obj -> obj
Public Function Insert (Optional Shift As Object, Optional CopyOrigin As Object) As Object

Parameters

Shift
Object

Specifies which way to shift the cells. Can be one of the following XlInsertShiftDirection values: xlShiftToRight or xlShiftDown. If this argument is omitted, Microsoft Office Excel decides based on the shape of the range.

CopyOrigin
Object

One of the XlInsertFormatOrigin values that specifies where to obtain the format to apply to the new cells.

Returns

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 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";
}
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

Remarks

Optional Parameters

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

Applies to