I'm trying to compare two worksheets in excel to find new/updated records using vba. (assume worksheet 1 is old, and worksheet 2 has the potential new/updated entries)
These sheets have very similar information stored in each, just in a different order.
For example: Worksheet 1 has Street Address in Column E whereas Worksheet 2 has the street Address in Column H. There are many other columns like this.
I'm not really sure where to start. I tried to rearrange the columns in the second sheet by cutting and inserting to match those of the first, but that got out of hand very quickly.
Also, if its a new record, it needs be appended to the end of the data.
**Updated to allow defining the 'key' column. Just change the line 'iKeyCol = 2' to the desired column.
Here is some code to try. I was too lazy to rework all the code I was using, so some of this may be extra for you. Make sure your workbook 1. Has at least three sheets (names 'Sheet1, Sheet2, NewSheet') 2. Has column headers for Sheet1 & Sheet2 3. Col1 must match in both sheets 4. Column count must match in both sheets. Other that col1, other columns can be in any order.
Paste the code into a new module and the execute.
Let me know if you have a problem.