Excel/Some Macro help


I am trying to create a macro to help me with a comparison.

I have 2 excel documents, each have one column which is similar (a code ID). I am trying to match up the code IDs from document 1 and document 2 and if there is a match create a new tab (for all the matches) and paste the code ID as well as another column (price) from document 2.

Any help would be greatly appreciated!


You can do what you want to do with a vlookup formula.

Your formula might look something like this


What this formula says is-- look up the value that is in the sheet named document 1 cell A2 in the Sheet named document 2 within the range A2 to B100 and if there is a match then return the value that is in column 1. where the match is.

In my document 1 sheet the A column is the code ID and the B column is the price.  the same is true in my document 2 sheet.  The formula is in the third sheet which I have named NEW TAB which also has the same column headings.  The formula can be copied down as far as you need it to go.

The second formula in the NEW TAB sheet is in column B or the price column.
this formula is very similar to the first except that it asks excel to return the value from the second column of the array, or column B, the price column.  That formula looks like this.

As you can see the only difference is the 2 which is just in front of the FALSE at the end of the formula.  The 2 refers to the second column of the array.

Now if you put these formulas in and copy them down, wherever there is not a match the error N/A will appear.  To eliminate that you can make the formula a bit more complicated and it will look like this.


This looks a lot more complicated but all it is doing is telling excel if there is an error (or no match) then put in a space or "", and if there is not an error (there is a match) then put in the value produced from the match.

You will have to change the column references in your formulas and the array references, but you should be able to use this basic formula to create your third NEW TAB sheet with all of the matched ID numbers.

Hope this helps

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Richard Roberts


Can assist you in most areas of Excel, have been working with it for about 15 years in many types of applications, but primarily in financial and accounting applications. I am a CPA and many client or client problems have necessitated the use of excel. I am not an expert in charting, macros, or pivot tables.


Have been working with Excel for about 20 years primarily in accounting and financial areas.

BA, Certified Public Accountant

©2017 About.com. All rights reserved.