Urgent Help: I get a daily log of data for which I want to run a VBA code to compare data in sheet 1 and sheet 2 and then copy common rows to another sheet, and unique rows to another sheet. Sheet 1 has the correct data, and sheet 2, is where I would like to look and find unique and duplicate rows.
Issue #1: I am unable to successfully do this for 100,000 plus rows as excel crashes.
Issue #2: I am unsure how to create a sheet for unique rows where there is no match.
Issue #3: Does no always copy duplicates.
Could someone help me make changes to this code to help meet it's functionality.
Issue #1: I am unable to successfully do this for 100,000 plus rows as excel crashes.
Issue #2: I am unsure how to create a sheet for unique rows where there is no match.
Issue #3: Does no always copy duplicates.
Could someone help me make changes to this code to help meet it's functionality.
VBA Code:
Sub Duplicate_Rows()
Dim ur1 As Range, ur2 As Range, dupeRows As Range
Dim r1 As Range, s1 As String, r2 As Range, s2 As String
Set ur1 = Worksheets("qry").UsedRange.Rows
Set ur2 = Worksheets("Dump").UsedRange.Rows 'Find duplicates from Sheet1 in Sheet2
Set dupeRows = ur2(Worksheets("Dump").UsedRange.Rows.Count + 1)
For Each r1 In ur1
s1 = Join(Application.Transpose(Application.Transpose(r1)))
For Each r2 In ur2
s2 = Join(Application.Transpose(Application.Transpose(r2)))
If s1 = s2 Then
If Intersect(dupeRows, r2) Is Nothing Then
Set dupeRows = Union(dupeRows, r2)
End If
End If
Next
Next
Dim wb As Workbook, wsDupes As Worksheet 'Move duplicate rows to new Sheet
Application.ScreenUpdating = False
Set wb = ThisWorkbook
Set wsDupes = wb.Worksheets.Add(After:=wb.Worksheets(wb.Worksheets.Count))
wsDupes.Name = "Dump Duplicates - " & Format(Now, "yyyymmdd-hhmmss")
dupeRows.Copy
With wsDupes.Cells(1)
.PasteSpecial xlPasteAll
.PasteSpecial xlPasteColumnWidths
.Select
End With
dupeRows.EntireRow.Delete
Application.ScreenUpdating = True
End Sub