Sub ConcatenateLines()
Dim shtData As Worksheet
Dim rowLast As Long
Dim rngData As Range, arrData As Variant
Dim dictData As Object, dictKey As String
Dim i As Long
Set shtData = Worksheets("Sheet1") ' <--- Change to your sheet name or use ActiveSheet
With shtData
rowLast = .Range("A" & Rows.Count).End(xlUp).Row
Set rngData = .Range("A9:B" & rowLast)
arrData = rngData.Value
End With
Set dictData = CreateObject("Scripting.dictionary")
dictData.CompareMode = vbTextCompare
' Load details range into Dictionary
For i = 1 To UBound(arrData)
dictKey = arrData(i, 1)
If Not dictData.exists(dictKey) Then
dictData(dictKey) = arrData(i, 2)
ElseIf dictData(dictKey) = "" Then
dictData(dictKey) = arrData(i, 2)
Else
dictData(dictKey) = dictData(dictKey) & ", " & arrData(i, 2)
End If
Next i
' Write output
rngData.ClearContents
rngData.Columns(1).Resize(dictData.Count).Value = Application.Transpose(dictData.keys)
rngData.Columns(2).Resize(dictData.Count).Value = Application.Transpose(dictData.items)
End Sub