先排序,最简单的就是逐行判断B列,如果本单元格内容和上一格相同,刚C列就等于上一格加上"/"再加上本列,如果不相同,就把B列内容和上面的内容写入另一个地方,最后就OK
Option Base 1
Sub sort()
Dim r As Integer
Dim j As Integer
Dim k() As Integer
Dim tnum As String
r = [b65536].End(xlUp).Row
Set d = CreateObject("scripting.dictionary")
j = 1
For i = 3 To r
Cells(i, 2) = Trim(Cells(i, 2))
Cells(i, 3) = Trim(Cells(i, 3))
If Cells(i, 2) = Cells(i - 1, 2) Then
ReDim Preserve k(j)
k(j) = i
j = j + 1
Else
If j > 1 Then
For a = k(1) - 1 To k(j - 1)
If Not d.exists(Cells(a, 3).Text) Then
d.Add Cells(a, 3).Text, ""
tnum = tnum & "/" & Cells(a, 3).Text
End If
Next
Range("C" & k(1) - 1 & ":C" & k(j - 1)).ClearContents
Range("C" & k(1) - 1 & ":C" & k(j - 1)).Merge
Range("C" & k(1) - 1 & ":C" & k(j - 1)) = Right(tnum, Len(tnum) - 1)
tnum = ""
d.RemoveAll
End If
j = 1
End If
Next
Set d = Nothing
End Sub