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
=VLOOKUP('DOCUMENT 1'!A2,'DOCUMENT 2'!A$2:B$100,1,FALSE)
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.
=VLOOKUP('DOCUMENT 1'!A2,'DOCUMENT 2'!A$2:B$100,2,FALSE)
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.
=IF(ISERROR(VLOOKUP('DOCUMENT 1'!A2,'DOCUMENT 2'!A$2:B$100,1,FALSE)),"",VLOOKUP('DOCUMENT 1'!A2,'DOCUMENT 2'!A$2:B$100,1,FALSE))
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