Consulting

Results 1 to 3 of 3

Thread: 2 lists, copy unique rows

  1. #1
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    1
    Location

    2 lists, copy unique rows

    Hi guys,

    I am a novice to marco/vba and am hoping to get some guidance on extracing unique values based on two lists(2 sheets).

    My scenario:
    • Sheet1 has one million lines of serial numbers (master sheet)
    • Sheet2 has 200,000 lines with same format. ColumnA=serial
    • sheet 2 has some new serials and some existing serials
    • Serial is 18 digit number saved as text (dunno of that matters)


    Solution?
    • how can I get vba to check serial agaisnt serial ( Sheet2 ColumnA against Sheet1 column A)
    • extract all new serials (unique of sheet 2 only)
    • unique lines to export to new sheet or replace sheet2


    I am really unsure how to start this... any ideas or pointers?

    I've googled my heart out for a week but haven't found anything that works.. I've found formulas& excel functions but they keep crashing my comp because of large data in sheet 1.

    Thanks in advance for any advice and your time!

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    can you attach a very small sample file with data and desired result ?

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome to the forum.

    you want to copy cells from Sheet2 to Sheet3 which are not present in Sheet1.

    this is a VBA solutioun which uses countif formula to detect nonmatching cells.

    i dont know how much time it took to complete the procedure.

    because i left the application after seeing in the progress bar that only 15% of the calculations are completed in 10 minutes with 8 processors.

    i assume A1 contains a header.

    Sub copy_nonmatching_cells()
    
        Dim Rng
        Dim Calc As Long
        
        With Application
            .DisplayAlerts = False
            .ScreenUpdating = False
            .EnableEvents = False
            Calc = .Calculation
            .Calculation = xlCalculationManual
        End With
        
        Set Rng = Worksheets("Sheet2").Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        
        With Rng
            .Offset(, 1).Formula = "=CountIf(Sheet1!A2:A1000000,A2)"
            .Calculate
            .Resize(, 2).AutoFilter , Field:=2, Criteria1:="0"
            .Parent.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet3").Range("A2")
            .AutoFilter
        End With
        
        With Application
            .EnableEvents = True
            .Calculation = Calc
        End With
    
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

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