我正在寻求一些帮助,我正在尝试找出一种从两个值中获取数据的方法,并显示另一个盒子中的差异。
实施例
A B
1 The cat and dog |
2 The and dog | cat
3 cat and dog | the
4 the cat | and dog
有什么想法吗?
答案 0 :(得分:5)
使用UDF:
Name
然后你会把它放在B1:
Function LeftOver(Str1 As String, Str2 As String) As String
Dim spltstr
For Each spltstr In Split(Str2)
Str1 = Trim(Replace(Str1, spltstr, "", , , vbTextCompare))
Next spltstr
LeftOver = Replace(Str1, " ", " ")
End Function
答案 1 :(得分:0)
使用VBA,您可以创建一个自定义函数,将minuend拆分为数组,将减数解析为字典,并循环通过minuend数组删除减数中的元素以返回差异。希望这很有帮助
答案 2 :(得分:0)
尝试这个小的用户定义函数:
Public Function WhatsMissing(s1 As String, s2 As String) As String
Dim IsInThere As Boolean
With Application.WorksheetFunction
ary1 = Split(.Trim(LCase(s1)), " ")
ary2 = Split(.Trim(LCase(s2)), " ")
End With
For Each a1 In ary1
IsInThere = False
For Each a2 In ary2
If a2 = a1 Then IsInThere = True
Next a2
If Not IsInThere Then WhatsMissing = WhatsMissing & " " & a1
Next a1
End Function