Range.ColumnDifferences method (Excel)

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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.