+ Reply to Thread
Results 1 to 8 of 8

VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

  1. #1
    Registered User
    Join Date
    06-12-2018
    Location
    New Hampshire, USA
    MS-Off Ver
    MS Office 2016
    Posts
    13

    VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    Hello Everyone.

    I have created a workbook that is being used to compare data between two worksheets (DataTable & HROlist). I have pieced together some VBA that works almost perfectly but I unable to make it work as desired. The goal is to compare the HROlist against the DataTable and if there is data in the HROlist not found in the DataTable, have it copied to Sheet3. Currently it has only copied 1 of three entries. The coding I am using is as follows:

    Please Login or Register  to view this content.
    I am hoping someone out there might be able to help me get back on track with this. I might just be over-thinking the problem.
    Attached Files Attached Files
    Last edited by NavyJack; 03-26-2019 at 06:36 AM. Reason: Added more test data to worksheet (HROlist).

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    That appears to be the only mismatch. What did you expect to see as a result?
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    06-12-2018
    Location
    New Hampshire, USA
    MS-Off Ver
    MS Office 2016
    Posts
    13

    Re: VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    On Sheet3 I expected to see the data copied for rows 5 and 6 (Peter Rabbit and Eric Clapton); however, it only copied the data for row 6 (P. Rabbit).

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    If you look at sheet 1, row 10, you will see that the Emp ID matches the Emp ID of Sheet 1, Row 5. That is why it did not copy over. The code is working as it should, it was your data that caused you to think it was not properly working. The names for the Emp ID are different on Sheet 1 and Sheet 2 for some items.
    Last edited by JLGWhiz; 03-25-2019 at 06:13 PM.

  5. #5
    Registered User
    Join Date
    06-12-2018
    Location
    New Hampshire, USA
    MS-Off Ver
    MS Office 2016
    Posts
    13

    Re: VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    JLGWhiz, Thank you for catching that, I'm not sure how I missed that when entering in test data. The code is still not working correctly however. I entered more random data into the HROlist worksheet (Sheet2) and the code still does not copy all the data to Sheet3.

    Something I did notice is that it copied only the last row of the data it found missing. Maybe I need to somehow incorporate a "For each" statement force the code to copy and paste each row that is missing the value in column H.

  6. #6
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    see if this will do what you want.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-12-2018
    Location
    New Hampshire, USA
    MS-Off Ver
    MS Office 2016
    Posts
    13

    Re: VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    JLGWhiz,

    You solved the problem, thank you. Your solution was much easier to read (and works as expected) than the direction I was going (that didn't work). I do my best to learn the coding by reading through the many posts on this forum to help me get different ideas for the many projects I have and to help me better understand VBA. Again, thank you for all the help.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to Compare Two Worksheets and Copy Missing Data into a 3rd Sheet

    Quote Originally Posted by NavyJack View Post
    JLGWhiz,

    You solved the problem, thank you. Your solution was much easier to read (and works as expected) than the direction I was going (that didn't work). I do my best to learn the coding by reading through the many posts on this forum to help me get different ideas for the many projects I have and to help me better understand VBA. Again, thank you for all the help.
    You're welcome,
    regards, JLG

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Compare two columns on separate sheet, if missing, insert missing data
    By lilvictorians in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-03-2019, 11:44 PM
  2. [SOLVED] compare two excel sheets and show missing data in a new sheet
    By jhonnyexcel in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 01-04-2016, 08:46 AM
  3. [SOLVED] Compare 2 sheets and add missing data from sheet2 to sheet 1 before certain row value
    By Risto85 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 07-03-2013, 09:40 AM
  4. Replies: 6
    Last Post: 06-07-2013, 06:42 AM
  5. compare two worksheets to find missing or incorrect data
    By moates in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 05-06-2013, 10:59 PM
  6. [SOLVED] Compare two workbooks and Copy missing data
    By Naba in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-29-2006, 02:10 AM
  7. Compare worksheets and generate list of missing data?
    By Minuette in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-03-2005, 09:45 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1