Sub duiying()
Dim i, j, found As Integer
Dim s As String
Cells(2, 8) = Cells(2, 5)
For i = 2 To Sheets(1).UsedRange.Rows.Count
found = 0
For j = 2 To Sheets(1).UsedRange.Rows.Count
If Cells(j, 8) = "" Then Exit For
If Cells(i, 5) = Cells(j, 8) Then
found = 1
End If
Next j
If found = 0 Then
Cells(j, 8) = Cells(i, 5)
End If
Next i
For i = 2 To Sheets(1).UsedRange.Rows.Count
If Cells(i, 8) = "" Then Exit For
s = ""
For j = 2 To Sheets(1).UsedRange.Rows.Count
If Cells(i, 8) = Cells(j, 5) Then s = s + CStr(Cells(j, 6)) + ","
Next j
s = Left(s, Len(s) - 1)
Cells(i, 9) = s
Next i
End Sub