j19_2002
05-17-2010, 01:43 PM
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!!
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
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!!
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