Here is the Macro:
Sub test()
Dim a, b(), i As Long, ii As Long, n As Long, z As String
With Range("a1").CurrentRegion.Resize(, 6)
a = .Value
ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
With CreateObject("Scripting.Dictionary")
.CompareMode = vbTextCompare
For i = 1 To UBound(a, 1)
z = a(i, 1) & ";" & a(i, 3) & ";" & a(i, 4)
If Not .exists(z) Then
n = n + 1 : .add z, n
End If
For ii = 1 To UBound(a, 2)
If ii <> 5 Then
If a(i, ii) <> "" Then b(.item(z), ii) = a(i, ii)
Else
b(.item(z), ii) = Trim(b(.item(z), ii) & " " & a(i, ii)
End If
Next
Next
End With
.Offset(, .Columns.Count + 1).Resize(n, UBound(b, 2)).Value = b
End With
End Sub
This is the data that it modifies:
FamilyName..Address1...FirstName...LastName...Relationship...... Phone #
10000001.....1234 Rd....John..........Doe...........Father..............1234
10000002....................John..........Doe..........Other.......... ......5678
10000002...5678 ln.......John..........Doe...........None .......................
10000003...2468..........Jane...........Doe...........Grandmother..... ..1234
And this is the output after the Macro is run:
FamilyName Address1...FirstName....LastName....Relationship........Phone #
10000001...1234 Rd.....John.............Doe .........Father...............1234
10000002...5678 ln......John.............Doe .........Other None........5678
10000003...2468.........Jane.............Doe .........Grandmother......1234
What the Macro does is it verifies that a row is a duplication by comparing: FamilyName , FirstName and LastName. Once it's verified the duplication, it combines data when there is a blank... for example, Row 2 (after being run through the Macro) now contains Address1 information AND Phone #. It also aggregates the Relationship column (notice Other and None being combined).
What I NEED it to do, is I need the aggregation to not happen if the Relationship data is the same (ie; if Rows 2 and 3 have "Mother", the macro makes the final row "Mother Mother" and I need it to just make it "Mother")
I also need the Address and Phone data that combines, to not only copy over blank cells, but also cells that say "Same".
Bookmarks