How to compare two Excel columns for differences? How to highlight the differences? Many times I find myself wanting to compare and see what changed between two excel files with similar content. Case 1 I got a file in an email from a co-worker that made some changes to a file I was working on? Doesn’t it happen all the time? Now I don’t know what changes he/she made. So either I reject my changes or I run the risk of losing his/her changes.
Case 2 I saved a file in two different locations and forgot which one has the latest changes. If you happen to fall into similar circumstances, you should definitely continue reading this post. Surprisingly, Microsoft Excel (2007-2013) doesn’t provide a way to compare two excel files like it is available in Microsoft Word. I created my own simple way of comparing two columns in Excel using VBA. There will be many ways you can do that, but it is my version of comparing two columns and highlight the changes. Below I have written a Microsoft Visual Basic Code (VBA), a macro, that you can freely use for yourself. Just copy/paste the code below and save that as a macro file.
If you want you can create a ribbon shortcut so you can get to it quickly(something I could explain in a future post.) VBA Code to compare two Excel columns Option Explicit Dim i As Integer, j As Integer Dim Col1 As Range, Col2 As Range Sub ExcelComparison 'Prompt for first column range selection. Set Col1 = Application.InputBox('Select First Column Range to Compare', Type:=8) 'Check if the range is only 1 column.
Comparing Two Excel Workbooks And If Columns Match Aug 15, 2014. I'm using two workbooks and looking to see if two columns match, then value in the cell should be the corresponding value of that cell. For example: I'm using If(Match(A2,'name of other workbook',0, I want the value in column F of row 2, 'not in raw data'). Open your Excel file, go to the View tab > Window group, and click the New Window. This will open the same Excel file in a different window. Enable View Side by Side mode by clicking the corresponding button on the ribbon.
If Col1.Columns.Count 1 Then Do Until Col1.Columns.Count = 1 MsgBox 'Please be certain to select only 1 column range.' Set Col1 = Application.InputBox('Select First Column Range to Compare', Type:=8) Loop End If 'Prompt for second column range selection. Set Col2 = Application.InputBox('Select Second Column range to Compare', Type:=8) 'Check if the range is only 1 column.
The one query that I get a lot is – ‘how to compare two columns in Excel?’. This can be done in many different ways, and the method to use will depend on the data structure and what the user wants from it. For example, you may want to compare two columns and find or highlight all the matching data points (that are in both the columns), or only the differences (where a data point is in one column and not in the other), etc. Since I get asked about this so much, I decided to write this massive tutorial with an intent to cover most (if not all) possible scenarios.
If you find this useful, do pass it on to other Excel users. This Tutorial Covers:. Note that the techniques to compare columns shown in this tutorial are not the only ones.
Based on your dataset, you may need to change or adjust the method. However, the basic principles would remain the same. If you think there is something that can be added to this tutorial, let me know in the comments section Compare Two Columns For Exact Row Match This one is the simplest form of comparison.
In this case, you need to do a row by row comparison and identify which rows have the same data and which ones does not. Example: Compare Cells in the Same Row Below is a data set where I need to check whether the name in column A is the same in column B or not. If there is a match, I need the result as “TRUE”, and if doesn’t match, then I need the result as “FALSE”.
![How How](/uploads/1/2/5/4/125419712/925736675.png)
The below formula would do this: =A2=B2 Example: Compare Cells in the Same Row (using IF formula) If you want to get a more descriptive result, you can use a to return “Match” when the names are the same and “Mismatch” when the names are different. =IF(A2=B2,'Match','Mismatch') Note: In case you want to make the comparison case sensitive, use the following IF formula: =IF(EXACT(A2,B2),'Match','Mismatch') With the above formula, ‘IBM’ and ‘ibm’ would be considered two different names and the above formula would return ‘Mismatch’. Example: Highlight Rows with Matching Data If you want to highlight the rows that have matching data (instead of getting the result in a separate column), you can do that by using. Here are the steps to do this:. Select the entire dataset.
Click the ‘Home’ tab. In the Styles group, click on the ‘Conditional Formatting’ option. From the drop-down, click on ‘New Rule’. In the ‘New Formatting Rule’ dialog box, click on the ‘Use a formula to determine which cells to format’. In the formula field, enter the formula: =$A1=$B1. Click the Format button and specify the format you want to apply to the matching cells. This will highlight all the cells where the names are the same in each row.
Compare Two Columns and Highlight Matches If you want to compare two columns and highlight matching data, you can use the duplicate functionality in conditional formatting. Note that this is different than what we have seen when comparing each row. In this case, we will not be doing a row by row comparison. Example: Compare Two Columns and Highlight Matching Data Often, you’ll get datasets where there are matches, but these may not be in the same row. Something as shown below: Note that the list in column A is bigger than the one in B.
![Machine Machine](/uploads/1/2/5/4/125419712/211674103.png)
Also some names are there in both the lists, but not in the same row (such as IBM, Adobe, Walmart). If you want to highlight all the matching company names, you can do that using conditional formatting.
Here are the steps to do this:. Select the entire data set.
Click the Home tab. In the Styles group, click on the ‘Conditional Formatting’ option. Hover the cursor on the Highlight Cell Rules option. Click on Duplicate Values. In the Duplicate Values dialog box, make sure ‘Duplicate’ is selected. Specify the formatting. The above steps would give you the result as shown below.
Note: Conditional Formatting duplicate rule is not case sensitive. So ‘Apple’ and ‘apple’ are considered the same and would be highlighted as duplicates. Example: Compare Two Columns and Highlight Mismatched Data In case you want to highlight the names which are present in one list and not the other, you can use the conditional formatting for this too. Select the entire data set. Click the Home tab.
In the Styles group, click on the ‘Conditional Formatting’ option. Hover the cursor on the Highlight Cell Rules option. Click on Duplicate Values. In the Duplicate Values dialog box, make sure ‘Unique’ is selected.
Specify the formatting. This will give you the result as shown below. It highlights all the cells that have a name that is not present on the other list. Compare Two Columns and Find Missing Data Points If you want to identify whether a data point from one list is present in the other list, you need to use the lookup formulas. Suppose you have a dataset as shown below and you want to identify companies that are present in column A but not in Column B, To do this, I can use the following. =ISERROR(VLOOKUP(A2,$B$2:$B$10,1,0)) This formula uses the VLOOKUP function to check whether a company name in A is present in column B or not.
If it is present, it will return that name from column B, else it will return a #N/A error. These names which return the #N/A error are the ones that are missing in Column B. ISERROR function would return TRUE if there is the VLOOKUP result is an error and FALSE if it isn’t an error. If you want to get a list of all the names where there is no match, you can filter the result column to get all cells with TRUE.
You can also use the MATCH function to do the same; =NOT(ISNUMBER(MATCH(A2,$B$2:$B$10,0))) Note: Personally, I prefer using the Match function (or the combination of Index/Match) instead of VLOOKUP. I find it more flexible and powerful. You can read the. Compare Two Columns and Pull the Matching Data If you have two datasets and you want to compare items in one list to the other and fetch the matching data point, you need to use the lookup formulas. Example: Pull the Matching Data (Exact) For example, in the below list, I want to fetch the market valuation value for column 2. To do this, I need to look up that value in column 1 and then fetch the corresponding market valuation value. Below is the formula that will do this: =VLOOKUP(D2,$A$2:$B$14,2,0) or =INDEX($A$2:$B$14,MATCH(D2,$A$2:$A$14,0),2) Example: Pull the Matching Data (Partial) In case you get a dataset where there is a minor difference in the names in the two columns, using the above-shown lookup formulas is not going to work.
These lookup formulas need an exact match to give the right result. There is an approximate match option in VLOOKUP or, but that can’t be used here. Suppose you have the data set as shown below. Note that there are names that are not complete in Column 2 (such as JPMorgan instead of JPMorgan Chase and Exxon instead of ExxonMobil). In such a case, you can use a partial lookup by using. The following formula will give is the right result in this case: =VLOOKUP('.'
&D2&'.' ,$A$2:$B$14,2,0) or =INDEX($A$2:$B$14,MATCH('.' &D2&'.'
,$A$2:$A$14,0),2) In the above example, asterisk (.) is a wildcard character that can represent any number of characters. When the lookup value is flanked with it on both sides, any value in Column 1 which contains the lookup value in Column 2 would be considered as a match. For example,.Exxon. would be a match for ExxonMobil (as. can represent any number of characters). You May Also Like the Following Excel Tips & Tutorials:.