Skip to main content

Range.ColumnDifferences method

Returns a Range object that represents all the cells whose contents are different from the comparison cell in each column.

Syntax

expression.ColumnDifferences (Comparison)

expression A variable that represents a Range object.

Parameters

Name Required/Optional Data type Description
Comparison Required Variant A single cell to compare to the specified range.

Return value

Range

Example

This example selects the cells in column A on Sheet1 whose contents are different from cell A4.

Sub CompDiff()
    'Setting up data to be compared
    Range("A1").Value = "Rod"
    Range("A2").Value = "Bill"
    Range("A3").Value = "John"
    Range("A4").Value = "Rod"
    Range("A5").Value = "Kelly"
    Range("A6").Value = "Rod"
    Range("A7").Value = "Paddy"
    Range("A8").Value = "Rod"
    Range("A9").Value = "Rod"
    Range("A10").Value = "Rod"
    
    'Code to do the comparison, selects the values that are unlike A1
    Worksheets("Sheet1").Activate
    Set r1 = ActiveSheet.Columns("A").ColumnDifferences(Comparison:=ActiveSheet.Range("A1"))
    r1.Select
End Sub

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>