NamedRange.Insert Method (Object, Object)


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)

object Insert(
	object Shift,
	object CopyOrigin


Type: System.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.

Type: System.Object

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

Return Value

Type: System.Object

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

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 =

    namedRange1.Value2 = "Raven";
Return to top