Hi, I have a report coming out of a database that lists my data in rows, resulting in multiple lines for each person shown below. I would like to concatenate the data in the fruit and extra fruit columns into a single row for each person. I have had a play with TEXTJOIN and have ended up using UniqConcat. I have the below VBA code, and this is working to concatenate the rows, but I need it to re-set each time the Unique ID changes. I was hoping that one of you amazing people could assist me with this?
My I want my spreadsheet looks like this so that I can then remove the duplicates and I am then left with one line per person.
VBA Code:
Function UniqConcat(rng As Range, str As String)
Dim ucoll As New Collection, Value As Variant, temp As String
On Error Resume Next
For Each Value In rng
If Len(Value) > 0 Then ucoll.Add Value, CStr(Value)
Next Value
On Error GoTo 0
For Each Value In ucoll
temp = temp & Value & str
Next Value
temp = Mid(temp, 1, Len(temp) - Len(str))
UniqConcat = temp
End Function
]
My I want my spreadsheet looks like this so that I can then remove the duplicates and I am then left with one line per person.
Last Name | First Name | ApplicationType | ExpiryDate | Facility | Fruit | Extra Fruit | Unique ID | Result | Extra Result |
Smith | James | New | 31/12/2020 | White House | Apple | Chicken | 803 | Apple, Orange | Chicken, Beef, Lamb |
Smith | James | New | 31/12/2020 | White House | Apple | Beef | 803 | Apple, Orange | Chicken, Beef, Lamb |
Smith | James | New | 31/12/2020 | White House | Apple | Lamb | 803 | Apple, Orange | Chicken, Beef, Lamb |
Smith | James | New | 31/12/2020 | White House | Orange | Chicken | 803 | Apple, Orange | Chicken, Beef, Lamb |
Smith | James | New | 31/12/2020 | White House | Orange | Beef | 803 | Apple, Orange | Chicken, Beef, Lamb |
Smith | James | New | 31/12/2020 | White House | Orange | Lamb | 803 | Apple, Orange | Chicken, Beef, Lamb |
Jones | Lucy | New | 31/12/2020 | White House | Plum | 804 | Plum, Mango, Pear | ||
Jones | Lucy | New | 31/12/2020 | White House | Mango | 804 | Plum, Mango, Pear | ||
Jones | Lucy | New | 31/12/2020 | White House | Pear | 804 | Plum, Mango, Pear |