это решение vba, я не объявлял переменные, пожалуйста, сделайте это
Sub a()
Set sh1 = Sheets(1)
Set sh2 = Sheets(2)
Lastrow2 = sh2.Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To Lastrow2
cable = sh2.Cells(r, 1)
s = ""
For Each cell In sh1.UsedRange
If cell = cable Then s = s + sh1.Cells(cell.Row, 1) + ","
Next
sh2.Cells(r, 2) = s
Next
End Sub