This documentation is archived and is not being maintained.

NamedRange.LocationInTable Property

Gets a constant that describes the part of the PivotTable report that contains the upper-left corner of the NamedRange control.

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

XlLocationInTable LocationInTable { get; }

The following code example creates a PivotTable report and a NamedRange inside the area of the PivotTable report. It then uses the PivotTable, LocationInTable, PivotCell, PivotItem, and PivotField properties to display information about the placement of the NamedRange within the PivotTable report. The example also uses the Group method to perform numeric grouping based on the first value in the field.

This example is for a document-level customization.

private void DisplayPivotTableInformation()
    // Specify values for the PivotTable.
    this.Range["A1", missing].Value2 = "Date";
    this.Range["A2", missing].Value2 = "March 1";
    this.Range["A3", missing].Value2 = "March 8";
    this.Range["A4", missing].Value2 = "March 15";

    this.Range["B1", missing].Value2 = "Customer";
    this.Range["B2", missing].Value2 = "Smith";
    this.Range["B3", missing].Value2 = "Jones";
    this.Range["B4", missing].Value2 = "James";

    this.Range["C1", missing].Value2 = "Sales";
    this.Range["C2", missing].Value2 = "23";
    this.Range["C3", missing].Value2 = "17";
    this.Range["C4", missing].Value2 = "39";

    // Create and populate the PivotTable.
    Excel.PivotTable table1 = this.PivotTableWizard(
        this.Range["A1", "C4"],
        this.Range["A10", missing], "Sales Table", false,
        false, true, false, missing, missing, false, false,
        Excel.XlOrder.xlDownThenOver, missing, missing, missing);

    Excel.PivotField customerField =
    customerField.Orientation =
    customerField.Position = 1;

    Excel.PivotField dateField =
    dateField.Orientation =
    dateField.Position = 1;

        "Sales Summary", Excel.XlConsolidationFunction.xlSum);

    // Create a NamedRange in the PivotTable and display the 
    // location.
    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Range["B11", missing], "namedRange1");

    MessageBox.Show("The NamedRange is in the PivotTable report '" +
        namedRange1.PivotTable.Name + "' at the location '" +
        namedRange1.LocationInTable.ToString() + "'.");

    MessageBox.Show("The NamedRange has a PivotCell type of: " +

    MessageBox.Show("The NamedRange is in the PivotTable field: " +

    MessageBox.Show("The NamedRange is in the PivotTable item: " +

    namedRange1.Group(true, missing, missing, missing);