|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
稍加修改即可
- Function Ref_diff(str1, str2 As String) As String
- Dim r As Range, dic As Object, arr1, arr2
- Set dic = CreateObject("scripting.dictionary")
- On Error Resume Next
- arr1 = Split(str1, ",")
- arr2 = Split(str2, ",")
- For i = 0 To UBound(arr1)
- If arr1(i) Like "*:*" Then
- For Each r In Range(arr1(i))
- dic(r.Address(0, 1)) = r.Address(0, 0)
- Next
- Else
- dic("$" & arr1(i)) = arr1(i)
- End If
- Next
- For i = 0 To UBound(arr2)
- If arr2(i) Like "*:*" Then
- For Each r In Range(arr2(i))
- If dic.exists(r.Address(1, 0)) Then
- dic(r.Address(0, 1)) = r.Address(0, 1)
- Else
- dic(r.Address(0, 0)) = r.Address
- End If
- Next
- Else
- If dic.exists("$" & arr2(i)) Then
- dic("$" & arr2(i)) = "$" & arr2(i)
- Else
- dic(arr2(i)) = "$" & arr2(i)
- End If
- End If
- Next
- arr1 = Join(Filter(dic.keys, "$", False), ",")
- arr2 = Join(Filter(dic.items, "$", False), ",")
- If arr1 <> "" Then Ref_diff = "Add " & arr1
- If arr2 <> "" Then Ref_diff = Ref_diff & " Del " & arr2
- Ref_diff = Replace(Trim(Ref_diff), " ", ";")
- Set dic = Nothing
- End Function
复制代码 |
|