+ Reply to Thread
Results 1 to 15 of 15

Compare two columns on separate sheet, if missing, insert missing data

  1. #1
    Registered User
    Join Date
    07-05-2012
    Location
    Oregon
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    56

    Compare two columns on separate sheet, if missing, insert missing data

    I've been searching for help for so long, and I thought I finally came across some code to do the job. The problem is that I'm not very experienced in VBA, so I'm still not able to get it to work.

    My process
    • Copy data range from Sample Data tab
    • Paste into Data tab
    • I'd like code which will compare the data in Column A of Data tab to Column A of Tracker tab, and then insert any missing data to the next available blank cell in Column A of Tracker tab.
    • The end result would be the same list of data in Columns A on both the Data and the Tracker tabs

    Here is the code I'm using (currently on the Data tab)
    HTML Code: 
    Any help would be greatly appreciated!!

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Compare two columns on separate sheet, if missing, insert missing data

    Solution 1

    Please Login or Register  to view this content.
    For every value from the Data worksheet a search will be performed on the Tracker worksheet, and the entry will be added when not found. It works but may be slow when comparing a large number of values


    Solution 2

    Please Login or Register  to view this content.
    Same concept but now using an keyed index (dictionary). More code but faster when processing large quantities
    If you like my contribution click the star icon!

  3. #3
    Registered User
    Join Date
    07-05-2012
    Location
    Oregon
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    56

    Re: Compare two columns on separate sheet, if missing, insert missing data

    OllieB - Thank you for your quick response! Two questions:
    1. Where should the code be stored?
    2. What do you consider a large number of values? I will have no more than 5,000 records in column A

  4. #4
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Compare two columns on separate sheet, if missing, insert missing data

    You should create a module in the VBA editor window. Use Alt-F11 to switch to the editor. I personally prefer solution 2

  5. #5
    Registered User
    Join Date
    07-05-2012
    Location
    Oregon
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    56

    Re: Compare two columns on separate sheet, if missing, insert missing data

    OllieB - I can't thank you enough. Your solution works flawlessly!

  6. #6
    Registered User
    Join Date
    07-05-2012
    Location
    Oregon
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    56

    Re: Compare two columns on separate sheet, if missing, insert missing data

    OllieB - Can you let me know what changes I'd need to make if I wanted everything to remain the same, EXCEPT to insert any missing data to the next available blank cells in Columns A AND B of Tracker tab? In other words, the validation to compare the lists would still be on Column A, but if missing from Tracker tab, it would insert both the Item number (Column A) and the Item Name (Column B).

    Column A is an item number
    Columns B is a corresponding item name

    Thank you again.

  7. #7
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Compare two columns on separate sheet, if missing, insert missing data

    Please try

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-05-2012
    Location
    Oregon
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    56

    Re: Compare two columns on separate sheet, if missing, insert missing data

    OllieB - That is brilliant, once again. Thank you!!

  9. #9
    Registered User
    Join Date
    07-05-2012
    Location
    Oregon
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    56

    Re: Compare two columns on separate sheet, if missing, insert missing data

    OllieB - I've been using your code and it's been working great. There is one small problem that I'm hoping you might be able to help with. The data in Column A are 6-digit ID numbers, many of which have leading zeroes. When the data from Column A of the Data tab are pasted in to Column A of the Tracker tab, the leading zeroes disappear. Column A in both tabs is formatted as text, which is what I want, in order for lookup formulas in other columns to work properly.

    Any suggestions?

  10. #10
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Compare two columns on separate sheet, if missing, insert missing data

    add this line

    Please Login or Register  to view this content.
    just before

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-05-2012
    Location
    Oregon
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    56

    Re: Compare two columns on separate sheet, if missing, insert missing data

    OllieB - That is PERFECT! I can't thank you enough. Appreciate you help and lightning fast responses.

  12. #12
    Registered User
    Join Date
    01-11-2014
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Compare two columns on separate sheet, if missing, insert missing data

    Hello All!

    I was hoping someone could help me find out where I am going wrong with this. I am trying to compare two lists doing exactly as the OP stated above, however I have 4 columns of data and each row is linked to each other. For example, I have data is A1:B1:C1:D1 and I need to compare this group with each line of data on the Tracker tab. I ran this code and ran into several problems:

    - If there is multiples of the same data in the DATA tab and only 1 set on the Tracker tab, it will insert another set of the data in the Tracker tab.
    - The code sometimes will not work at all.

    Basically what I am trying to do is gather 7 days of data (that will have the same values on certain days) and compile it into one master list to use. Anyone have any ideas?

    Please Login or Register  to view this content.

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Compare two columns on separate sheet, if missing, insert missing data

    effektz,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  14. #14
    Registered User
    Join Date
    04-03-2019
    Location
    Sweden
    MS-Off Ver
    2016
    Posts
    1

    Re: Compare two columns on separate sheet, if missing, insert missing data

    I have data in two sheets. How do I use the code here to compare the data in second sheet with the first sheet and insert the missing data in the second sheet
    Last edited by Jane.Pottipadu; 04-03-2019 at 04:17 AM.

  15. #15
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,929

    Re: Compare two columns on separate sheet, if missing, insert missing data

    Jane, did you miss the thread immediately above yours??

    We are happy to help, however whilst you feel your request is similar to this thread, experience has shown that things soon get confusing when answers refer to particular cells/ranges/sheets which are unique to your post and not relevant to the original. Please start a new thread - See Forum rule #4

    If you are not familiar with how to start a new thread see the FAQ: How to start a new thread
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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