+ Reply to Thread
Results 1 to 9 of 9

Copmaring two lists and extracting all unequal rows

  1. #1
    Registered User
    Join Date
    10-11-2012
    Location
    switzerland
    MS-Off Ver
    Excel 2010
    Posts
    38

    Copmaring two lists and extracting all unequal rows

    Hello everyone

    I've managed to solve this problem with formulas but they are slowing down my workbook as excel needs ~2mb for a list of about 2000x150 cells.
    So, I thought there might be an easy solution in VBA?

    Let's say, I have a "Sheet1" with the list

    A B
    1 Txt1 Txt3
    2 Txt2 Txt4

    and a "Sheet2" with the list

    A B
    1 Txt1 Txt3
    2 Txt2 Bla

    What do I want to achieve?

    In "Sheet 3" I want to extract all rows from the list in "Sheet2" that are different from the rows in the list in "Sheet1" (at least in one cell).
    That would give me:

    A B
    1 Txt2 Bla

    As my full list contains plenty of empty cells, it would be cool if I didn't have to put code into every cell to check for equality.

    Thank you in advance
    I appreciate the help here a lot

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

    Re: Copmaring two lists and extracting all unequal rows

    Does your original file also have the same number of columns (3) ?

    Also, which is the common field between both the sheets?
    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]

  3. #3
    Registered User
    Join Date
    10-11-2012
    Location
    switzerland
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Copmaring two lists and extracting all unequal rows

    No, the original file has two sheets each with 2000 rows and 150 columns (might grow in the future). I am trying to extract all rows from the list in the 2nd sheet that have at least one different cell entry as in the 1st sheet. The "filtered" and thus smaller list should be shown in the 3rd sheet.

    The two lists have the exact same column names. They only have different entries (e.g. list one in Sheet1!D10 equals "TRUE" whereas the same cell in Sheet2 is empty).

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

    Re: Copmaring two lists and extracting all unequal rows

    So each column has to be compared with the other column from the 2nd sheet?

  5. #5
    Registered User
    Join Date
    10-11-2012
    Location
    switzerland
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Copmaring two lists and extracting all unequal rows

    Well, see, this is the conditional formatting I use to color the unequal cells:

    =IF(Sheet1!A1=A1;0;1)

    The above formula colors me every cell in Sheet2 which is different from the exact same cell in Sheet1.
    That is perfect so far.

    What I'd like to achieve now, is:

    "Copy every row in Sheet2 which is different to the exact same row in Sheet1 to Sheet3"

    So, in that sense I think I should be checking the rows instead of the columns, or? That is my question here. How should I be checking it?

    - Checking all cells forces 300'000 formulas to trigger (= very slow)
    - I have not yet seen a function in Excel that compares whole arrays or lists

    That's why I thouhgt there might be an easy VBA solution, if only I knew how to use it

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

    Re: Copmaring two lists and extracting all unequal rows

    Sure, i can help you out if you can give me more information. Can i use the color of the cells to check for discrepancies? I mean, if i find even once cell in the row having that color that you apply using conditional formatting, it should stop checking the rest of the cells in that row and copy that row to sheet3.

    Why dont you attach a sample file? It may be clear after seeing it.

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  7. #7
    Registered User
    Join Date
    10-11-2012
    Location
    switzerland
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Copmaring two lists and extracting all unequal rows

    Ok

    As you can see, in the teststuff.xlsx, I'd like to have the rows 14, 16 to 21 copied into the 3rd sheet.

    Is it possible with VBA?

    Thanks
    Attached Files Attached Files

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

    Re: Copmaring two lists and extracting all unequal rows

    Try this code
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

    Note: I used a worksheet called "Temp" to do the comparisons. The macro needed a common field between both the sheets, so i inserted serial numbers in both sheets which were later deleted. The output is in Sheet3.

  9. #9
    Registered User
    Join Date
    10-11-2012
    Location
    switzerland
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Copmaring two lists and extracting all unequal rows

    Hey arlu1201

    Thank you very much. I managed to solve it differently, but some of your code snippets look very interesting for future use.
    The whole wishes for my sheet have changed, so at the moment I am occupied with other things.

    I'll see how much of this code I can use once I face my new "realities".
    I'll get in touch

    Thanks again

+ 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