NamedRange.RowDifferences(Object) Method

Definition

Gets a Range object that represents all the cells whose contents are different from those of the comparison cell in each row.

public:
 Microsoft::Office::Interop::Excel::Range ^ RowDifferences(System::Object ^ Comparison);
public Microsoft.Office.Interop.Excel.Range RowDifferences (object Comparison);
abstract member RowDifferences : obj -> Microsoft.Office.Interop.Excel.Range
Public Function RowDifferences (Comparison As Object) As Range

Parameters

Comparison
Object

A single cell to compare with the other cells in the row.

Returns

A Range object that represents all the cells whose contents are different from those of the comparison cell in each row.

Examples

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

This example is for a document-level customization.

private void ShowRowDifferences()
{
    Microsoft.Office.Tools.Excel.NamedRange rowDifferencesRange =
       this.Controls.AddNamedRange(this.Range["A1", "C5"],
       "rowDifferencesRange");
    this.Range["A1", "A5"].Value2 = 11;
    this.Range["B1", "B5"].Value2 = 22;
    this.Range["C1", "C5"].Value2 = 33;
    Excel.Range range2 = rowDifferencesRange.RowDifferences(
        this.Range["B5"]);
    range2.Select();
}
Private Sub ShowRowDifferences()
    Dim rowDifferencesRange As _
        Microsoft.Office.Tools.Excel.NamedRange = _
        Me.Controls.AddNamedRange(Me.Range("A1", "C5"), _
        "rowDifferencesRange")
    Me.Range("A1", "A5").Value2 = 11
    Me.Range("B1", "B5").Value2 = 22
    Me.Range("C1", "C5").Value2 = 33
    Dim range2 As Excel.Range = _
        rowDifferencesRange.RowDifferences(Me.Range("B5"))
    range2.Select()
End Sub

Applies to