NamedRange.Delete Method

Deletes a dynamically created NamedRange control and removes it from the ControlCollection.

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

void Delete()

This method should only be used with a NamedRange control that is created programmatically at run time. An exception is thrown if you call this method on a NamedRange control that is added to the document at design time.

The following code example sets a NamedRange control that includes cells A1 through A5 to random values, and then uses the Delete method to remove the NamedRange control. Note that although the NamedRange control is deleted, cells A1 through A5 retain their values.

This example is for a document-level customization.

private void DeleteRange()
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
    namedRange1.Formula = "=rand()";


Community Additions