Consulting

Results 1 to 7 of 7

Thread: Duplicates and Deletes

  1. #1
    VBAX Regular
    Joined
    Sep 2008
    Posts
    39
    Location

    Duplicates and Deletes

    Having a problem with code to identify duplicate entries using worksheets named "2010" & "2009". Once duplicates have been identified I am trying to have the entire row cut from sheet "2010" and than pasted into sheet "Duplicates".

    I keep getting an error once I run it:
    Code execution has been interrupted

    When i click debug it highlights: .Rows(i).Delete
    Below is the code I am using:

    Also I have attached an example of how the original excel worksheet is set.
    Someone please help...Thank You!!

    [vba]Public Sub ProcessData()
    Dim i As Long
    Dim LastRow As Long
    Dim NextRow As Long
    Dim shMatch As Worksheet
    Dim shCopy As Worksheet

    Set shMatch = Worksheets("2010")
    Set shCopy = Worksheets("Duplicates")
    With Worksheets("2009")

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For i = LastRow To 1 Step -1

    If Not IsError(Application.Match(.Cells(i, "A").Value, shMatch.Columns(1), 0)) Then

    NextRow = NextRow + 1
    .Rows(i).Copy shCopy.Rows(NextRow)
    .Rows(i).Delete
    End If
    Next i

    End With
    End Sub[/vba]
    Last edited by j19_2002; 05-17-2010 at 02:35 PM.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    try .Rows(i).EntireRow.Delete
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Regular
    Joined
    Sep 2008
    Posts
    39
    Location
    Tried it, now it's giving me another error on the next line: End If

    And if I click to continue, it continues to run the macro and find entries one by one but it always stops on the: End If

  4. #4
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    The code as you originally posted it works fine with no errors, can you post the problematic workbook?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  5. #5
    VBAX Regular
    Joined
    Sep 2008
    Posts
    39
    Location
    Ok I have attached the workbook but had to delete about 10k entries since it was too big, still creating the error though.

    Essentially just trying to scan 2010 against 2009 to find entries already done in 2009 and cut them from 2010 and paste them in duplicates sheet.

    Thank for all your help!

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Works perfect for me as you have it, what is the error exactly?
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    The reason your workbook is so large is because you have formatted ALL of the 65536 rows available to you!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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