+ Reply to Thread
Results 1 to 9 of 9

Compare and copy two columns from each sheet in a workbook

  1. #1
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Compare and copy two columns from each sheet in a workbook

    I have got an excel sheet that has got 3 sheets in a single workbook.

    I need a macro that would compare the 2 columns with same headers in the 1st and 2nd sheet (i.e. compare column A and B of sheet ABC with the Column A and B of the Sheet DEF) and only if both the values in column A and B of the sheet ABC matches the values of columns A & B in sheet DEF, copy the matched data from 1st sheet along with its corresponding values in column C in the 2nd sheet to the 3rd sheet(GFH).

    Sorry for too complicated explanation! Hope this is understandable.

    Thank you.
    Attached Files Attached Files

  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: Compare and copy two columns from each sheet in a workbook

    See if this does what you want
    Please Login or Register  to view this content.
    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
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Compare and copy two columns from each sheet in a workbook

    Hi Sara,

    You can do this problem without using VBA using a helper column and this formula in it (On sheet 2 - Column D).

    =MATCH(A2&B2,(ABC!A:A&ABC!B:B),0)

    You need to enter the above as an Array Formula using Control+Shift+Enter and then copy the formula down.

    All the rows where column D is a number are the ones you want to copy to the third sheet.

    Hope that helps...
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,519

    Re: Compare and copy two columns from each sheet in a workbook

    Or
    Please Login or Register  to view this content.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Compare and copy two columns from each sheet in a workbook

    Another one.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  6. #6
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Compare and copy two columns from each sheet in a workbook

    Quote Originally Posted by jolivanes View Post
    Or
    Please Login or Register  to view this content.
    Thank you jolivanes, it worked perfectly

  7. #7
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Compare and copy two columns from each sheet in a workbook

    Quote Originally Posted by bakerman2 View Post
    Another one.
    Please Login or Register  to view this content.
    Thank you bakerman2, your code was faster and works well too. Only thing is that i need the compared data to be copied in the order of the 1st sheet (ABC)

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,519

    Re: Compare and copy two columns from each sheet in a workbook

    Try
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Compare and copy two columns from each sheet in a workbook

    Quote Originally Posted by jindon View Post
    Try
    Please Login or Register  to view this content.
    Amazing!!!! this gets the work done in a second. Thanks a lot jindon!

+ 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. Compare two columns from two sheets, copy entire row from one sheet to the other
    By amjwh99 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2017, 03:39 PM
  2. Replies: 4
    Last Post: 08-03-2017, 04:31 PM
  3. Compare Sheets In Workbook Copy To Sheet Three
    By gaspower in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-24-2015, 11:54 AM
  4. Replies: 0
    Last Post: 11-25-2014, 05:30 PM
  5. [SOLVED] COPY from an open workbook with particular sheet and columns to active workbook
    By purin0c0 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-12-2012, 03:57 PM
  6. Compare Two Columns in Separate Sheets and copy fields over to third sheet
    By initiator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2010, 09:23 AM
  7. Compare columns in 2 sheets in the same workbook and copy HELP NEEDED
    By ktab in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2005, 08:23 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