' 函数开始 Function RemoveDuplicates(cell As Range) As String Dim items As Object Dim arr() As String Dim output As String Dim i As Long
' 创建字典对象用于去重 Set items = CreateObject("Scripting.Dictionary")
' 将单元格内容按逗号拆分为数组 arr = Split(cell.Value, ",")
' 遍历数组,将唯一值添加到字典 For i = LBound(arr) To UBound(arr) arr(i) = Trim(arr(i)) ' 去除多余的空格 If Not items.exists(arr(i)) Then items.Add arr(i), True End If Next i
' 将字典中的键合并为字符串 output = Join(items.keys, ",")
' 返回去重后的结果 RemoveDuplicates = output End Function ' 函数结束