Glory
Well-known Member
- Joined
- Mar 16, 2011
- Messages
- 640
Code:
Sub CompileList()
'Building lists in Sheet4, columns A-C
'Source is Sheets1-3, column A
For e = 1 To 3
theRow3 = 1
If e = 1 Then: Set a = ThisWorkbook.Sheets("Sheet1")
If e = 2 Then: Set a = ThisWorkbook.Sheets("Sheet2")
If e = 3 Then: Set a = ThisWorkbook.Sheets("Sheet3")
Set b = ThisWorkbook.Sheets("Sheet4")
theRow1 = a.Range("A" & a.Range("A" & Rows.Count).End(xlUp).Row).Row
If theRow1 < 2 Then: Exit Sub
For c = 2 To theRow1
theRow2 = b.Cells(b.Cells(Rows.Count, e).End(xlUp).Row, e).Row
If theRow2 < 2 Then: theRow2 = 2
For d = 2 To theRow2
If a.Cells(c, 1) = b.Cells(d, e) Then
GoTo theNext1
End If
Next
theRow3 = theRow3 + 1
b.Cells(theRow3, e) = a.Cells(c, 1)
theNext1:
Next
Next
'Building list in Sheet4, column E
'Source is Sheet4, columns A-C
theRow3 = 2
For e = 1 To 3
theRow1 = b.Cells(b.Cells(Rows.Count, e).End(xlUp).Row, e).Row
If theRow1 < 2 Then: Exit Sub
For c = 2 To theRow1
theRow3 = b.Cells(b.Range("E" & Rows.Count).End(xlUp).Row, e).Row
For d = 2 To theRow3
If b.Cells(c, e) = b.Cells(d, 5) Then
GoTo theNext2
End If
Next
b.Cells(theRow3 + 1, 5) = b.Cells(c, e)
theNext2:
Next
Next
End Sub
Sheets 1-3 have contents in column A. Many duplicates are present.
The code copies non-duplicate entries to sheet4.
Column A in Sheet1 fills column A in Sheet4.
Column A in Sheet2 fills column B in Sheet4.
Column A in Sheet3 fills column C in Sheet4.
When the first three loops are finished, the code moves on, parsing the three lists in sheet four to produce a final list of non-duplicate entries in column E of sheet4.
I'm wondering if there are any obvious problems that I'm missing that are going to crop up and cause issues with lost information later on.