ColumnDifferences Method
Collapse the table of content
Expand the table of content

NamedRange.ColumnDifferences Method (Object)

 

Gets a Microsoft.Office.Interop.Excel.Range that represents all the cells whose contents are different from the comparison cell in each column.

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

Range ColumnDifferences(
	object Comparison
)

Parameters

Comparison
Type: System.Object

A single cell to compare to the specified range.

Return Value

Type: Microsoft.Office.Interop.Excel.Range

A Microsoft.Office.Interop.Excel.Range that represents all the cells whose contents are different from the comparison cell in each column.

The following code example creates a NamedRange and populates cells in the range with two different values. It compares all of the cells in the NamedRange with the value of cell B5, which is 11, and selects the cells with values that do not match.

This example is for a document-level customization.

private void ShowColumnDifferences()
{
    Microsoft.Office.Tools.Excel.NamedRange columnDifferencesRange =
       this.Controls.AddNamedRange(this.Range["A1", "C5"],
       "columnDifferencesRange");
    this.Range["B1", "C3"].Value2 = 22;
    this.Range["B4", "C5"].Value2 = 11;
    Excel.Range range2 = columnDifferencesRange.ColumnDifferences(
        this.Range["B5"]);
    range2.Select();
}
Return to top
Show:
© 2016 Microsoft