You don't need a VBA Macro to solve this. That will turn out to be much slower than using the built-in VLOOKUP.
Let's start with 2 worksheets (as you say): Sheet1 and Sheet2. The first two columns of each sheet is the name and value.
Sheet1:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
Item[/TD]
[TD]
Price[/TD]
[/TR]
[TR]
[TD]Item A[/TD]
[TD]$49.95[/TD]
[/TR]
[TR]
[TD]Item B[/TD]
[TD]$16.99[/TD]
[/TR]
[TR]
[TD]Item C[/TD]
[TD]$12.49[/TD]
[/TR]
</tbody>[/TABLE]
and so on.
Sheet2:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
Item[/TD]
[TD]
Price[/TD]
[/TR]
[TR]
[TD]Item A[/TD]
[TD]$49.95[/TD]
[/TR]
[TR]
[TD]Item C[/TD]
[TD]$12.99[/TD]
[/TR]
[TR]
[TD]Item D[/TD]
[TD]$19.99[/TD]
[/TR]
</tbody>[/TABLE]
etc.
What you do, is add another column after the first two in Sheet1. This new column will show the price in the other sheet. If the item does not exist in the other sheet, it will be left blank.
Sheet1:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
Item[/TD]
[TD]
Price[/TD]
[TD]
Sheet2 Price
[/TD]
[/TR]
[TR]
[TD]Item A[/TD]
[TD]$49.95[/TD]
[TD]$49.95
[/TD]
[/TR]
[TR]
[TD]Item B[/TD]
[TD]$16.99[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Item C[/TD]
[TD]$12.49[/TD]
[TD]$12.99[/TD]
[/TR]
</tbody>[/TABLE]
and so on. The formula in C2 ($49.95: the Sheet2 price for Item A) is:
Code:
=IfError(VLOOKUP(A2, Sheet2!$A:$B, 2, False),"")
The VLOOKUP looks for the value from A2 (Item A) in the first column of the range in the second argument. If it finds it, it returns column 2 of that row. The False at the end tells VLOOKUP to check every item in a linear search until it finds what it is looking for. If VLOOKUP cannot find the value in the first column, it returns #N/A. The IFERROR function looks at the value from its first argument and if it returns an error, like #N/A, then it returns the second argument instead, which in this case is blank. Copy this formula and paste in the entire column for your table.
To make it more obvious that the prices are different, you could add a conditional format. Select the Sheet2 Price column (C). Click on Data - Conditional Format. Choose Highlight Cell Rules - Equal To. Click on the selection button on the end of the first text-box and click on A2. Make sure the row number does not have a dollar sign on it. The text-box should contain
=$A2 . Click OK.
You will notice that the cells that are highlighted are the ones that match; we want to change the conditional format so that the highlighted cells are the ones that do not match. Click on Conditional Format again and select Manage Rules. Make sure the rule you just created is selected and click on Edit Rule. Find the combo box that says "equal to". Click on the drop-down button and select "not equal to". Click Ok. Keep clicking Ok until you are back at your worksheet. All the mismatches should now be highlighted in red.
I had you go through the Conditional Format twice as that was the easy way to assign that style for the mismatches.
Sheet1:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]
Item[/TD]
[TD]
Price[/TD]
[TD]
Sheet2 Price[/TD]
[/TR]
[TR]
[TD]Item A[/TD]
[TD]$49.95[/TD]
[TD]$49.95
[/TD]
[/TR]
[TR]
[TD]Item B[/TD]
[TD]$16.99[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Item C[/TD]
[TD]$12.49[/TD]
[TD]
$12.99[/TD]
[/TR]
</tbody>[/TABLE]
You could then filter for red text on column C to find the mismatches.