The code requires the user to select columns in a single range.
If not omitted, the Option Compare setting will determine the type of comparison. Note that the third argument is optional. First 2 arguments are the strings to be compared, and the last one is the comparison type. Zero ' 0' means a perfect match, and the sample code we give below highlights the cell if the result is NOT equal to 0. This function returns an integer based on the result of the comparison.
VBA has a built in function called StrComp, which can compare two separate strings. Let us show you how to compare two columns in Excel using VBA and automate this process. Comparing columns of data manually is not a realistic approach when working with large data sets.