你可以利用:
如下:
Option Explicit
Sub main()
Dim iRow As Long
Dim codeKey As Variant, persons As Variant
Dim codesRng As Range
Set codesRng = Range("C3", Cells(Rows.count, 3).End(xlUp)) '<--| set the range with all codes
Normalize codesRng '<--| rewrite codes with only one delimiter
With CreateObject("Scripting.Dictionary") '<--| instantiate a 'Dictionary' object
For iRow = 1 To codesRng.Rows.count '<--| loop through 'codesRng' cells
codeKey = GetKey(codesRng(iRow, 1)) '<--| get its "Key"
.item(codeKey) = .item(codeKey) & codesRng(iRow, 1).Offset(, -2) & "|" '<--| update current 'codeKey' dictionary item with the corresponding "person"
Next
For Each codeKey In .Keys '<--| loop through dictionary keys
persons = Split(Left(.item(codeKey), Len(.item(codeKey)) - 1), "|") '<--| get current key array of "persons"
If UBound(persons) > 0 Then Debug.Print Join(persons, ",") '<--| print them if more than one person
Next
End With '<--| release 'Dictionary' object
End Sub
Sub Normalize(rng As Range)
With rng
.Replace " ", "", xlPart
.Replace "+-", "+", xlPart
.Replace "(", "", xlPart
.Replace ")", "", xlPart
.Replace "/", "+", xlPart
.Replace "+Ax", "Ax", xlPart
.Replace "+", "|", xlPart
End With
End Sub
Function GetKey(strng As String) As Variant
Dim elements As Variant
Dim j As Long
elements = Split(strng, "|") '<--| get an array of values out of those found delimited by a pipe ("|") in the string
With CreateObject("System.Collections.SortedList") '<--| instantiate a 'SortedList' object
For j = 0 To UBound(elements) '<--| loop through array values
.item(CStr(elements(j))) = "" '<--| add them to 'SortedList' object
Next
For j = 0 To .count - 1 '<--| iterate through 'SortedList' object elements
elements(j) = .GetKey(j) '<--| write back array values in sorted order
Next
End With '<--| release 'SortedList' object
GetKey = Join(elements, "|") '<--| return the "Key" as a string obtained from the passed one sorted values
End Function