Column Differences Method Excel Add-in VBA example

Column Differences Method Excel Add-in VBA example

ColumnDifferences

Column Differences is a method which determines differences against given match criteria range. This method take Comparison argument which should be a Range object, needs to be compared and returns a Range object.

Expression

expression.ColumnDifferences(Comparision)

Data source

Code example

Public Sub ColumnDifferenceExample()
    'object to bind selection
    Dim oSourceRange As Range
    'Bind selection to range object
    Set oSourceRange = Selection
    
    'object to be matched
    Dim oRangeToMatch As Range
    
    'Bind range
    Set oRangeToMatch = Range("A2")
    
    'object to hold difference result
    Dim oUniqueRange As Range
    
    'Perform difference
    Set oUniqueRange = oSourceRange.ColumnDifferences(oRangeToMatch)
    
    'Select the range found different
    oUniqueRange.Select
    
    'Format font color
    oUniqueRange.Font.Color = vbRed
    
    'Fill cell beackground
    oUniqueRange.Interior.Color = vbBlue
    
    'Memory cleanup
    Set oSourceRange = Nothing
    Set oRangeToMatch = Nothing
    Set oUniqueRange = Nothing
    
End Sub

Explanation

Above code will will match range A2 which has “VBAOVERALL” as cell content and does a comparison over Range A2:A7 and perform formatting like Cell background color change, font color change and select the same:

Output

Please leave your comments or queries under comment section also please do subscribe to our blogs to keep your self upto date.

Leave a Reply

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