I am trying to group duplicate rows according to Column 3(ID Number). I have used collections as a method, The problem is if there is only two duplicates in column three then only one item shows up in the watch window of the collection.I have posted the result that I want on the right hand side of the excel xl2bb. I am fairly new to vba. I also want to write it out onto the worksheet but has issues.Here is what I have so far:
Sub Duplicate()
Dim coll As New Collection, cls As Class1
Dim arrayDup() As Variant
Dim a As Long, b As Long, rw As Long, cl As Long, s As Long, k As Long
rw = Sheet1.Range("A1").CurrentRegion.Rows.Count
cl = Sheet1.Range("A1").CurrentRegion.Columns.Count
arrayDup = Sheet1.Range("A1").CurrentRegion.Value
For a = 2 To UBound(arrayDup) - 1
For b = a To UBound(arrayDup) - 1
If arrayDup(a, 3) = arrayDup(b + 1, 3) Then
Set cls = New Class1
cls.FullName = arrayDup(b + 1, 1)
cls.LastName = arrayDup(b + 1, 2)
cls.IDNumber = arrayDup(b + 1, 3)
coll.Add cls
End If
Next b
Next a
End Sub
Sub Duplicate()
Dim coll As New Collection, cls As Class1
Dim arrayDup() As Variant
Dim a As Long, b As Long, rw As Long, cl As Long, s As Long, k As Long
rw = Sheet1.Range("A1").CurrentRegion.Rows.Count
cl = Sheet1.Range("A1").CurrentRegion.Columns.Count
arrayDup = Sheet1.Range("A1").CurrentRegion.Value
For a = 2 To UBound(arrayDup) - 1
For b = a To UBound(arrayDup) - 1
If arrayDup(a, 3) = arrayDup(b + 1, 3) Then
Set cls = New Class1
cls.FullName = arrayDup(b + 1, 1)
cls.LastName = arrayDup(b + 1, 2)
cls.IDNumber = arrayDup(b + 1, 3)
coll.Add cls
End If
Next b
Next a
End Sub
arrange (version 1).xlsb | |||||||||
---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | |||
1 | First Name | LastName | IDNumber | >>>>> | First Name | LastName | IDNumber | ||
2 | Sea | west | 6 | Sea | west | 6 | |||
3 | Kicker | east | 6 | Kicker | east | 6 | |||
4 | Police | north | 9 | Shia | moody | 6 | |||
5 | Dan | south | 3 | Dan | south | 3 | |||
6 | Ban | north west | 3 | Ban | north west | 3 | |||
7 | Shia | moody | 6 | Police | north | 9 | |||
8 | Kakah | hoodie | 10 | Kakah | hoodie | 10 | |||
Sheet1 |