Export (0) Print
Expand All
Expand Minimize

Worksheet.ConsolidationSources Property (2007 System)

Gets an Array of strings that name the source sheets and ranges for the worksheet's current consolidation.

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

[BrowsableAttribute(false)]
public Object ConsolidationSources { get; }

Property Value

Type: System.Object
An Array of string values that name the source sheets and ranges for the worksheet's current consolidation; null if there is no consolidation on the sheet.

The following code example creates a consolidation on the current worksheet, and then uses the ConsolidationSources property to display the sources of the consolidation.

This example is for a document-level customization.

private void ShowConsolidationSources()
{
    // Popluate the data to be consolidated. 
    this.Range["A1", missing].Value2 = 22;
    this.Range["A2", missing].Value2 = 33;
    string[] sourceStrings = new string[] { "Sheet1!R1C1", 
        "Sheet1!R2C1" };

    // Consoldate the data by adding it together. 
    this.Range["A3", missing].Consolidate(sourceStrings,
        Excel.XlConsolidationFunction.xlSum, false, false, false);

    // Display the sources of the consolidated data. 
    if (this.ConsolidationSources != null)
    {
        this.Range["C1", missing].Value2 = "Consolidation Sources";
        Array sources = (Array)this.ConsolidationSources;

        if (sources.Length != 0)
        {
            for (int i = 1; i <= sources.Length; i++)
            {
                this.Range["C" + (i + 1).ToString(),
                    missing].Value2 = sources.GetValue(i);
            }
        }
        else
        {
            this.Range["C2", missing].Value2 = "None";
        }
    }
    else
    {
        MessageBox.Show("This worksheet has no consolidation.");
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft