2017-01-04 49 views
0

我正在寻找一些帮助,我试图找出一种方法来从两个值中获取数据并显示另一个框中的区别。Excel - 显示缺失值

 A       B 
1 The cat and dog   | 
2 The and dog    | cat 
3 cat and dog    | the 
4 the cat     | and dog 

任何想法?

+0

完美的结果应该是“猫和狗”,如果不显示该领域缺少的东西。 – Piglet

+0

它不直截了当? A1正在展示猫和狗,因此在B1中没有任何东西,因为它是完美的陈述。 A2“狗和狗”缺少的是在B2中显示的“猫”,因为它不是正确的说法。 – Piglet

回答

5

使用UDF:

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 

然后,你会把这B1:

=LeftOver($A$1,A1) 

enter image description here

+0

谢谢,这个作品很棒:)! – Piglet

0

使用VBA,您可以创建一个自定义函数,将被减数分解为一个数组,将减数解析为一个字典,并通过被减数组循环来移除减数中的元素以返回差异。希望对您有所帮助

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 

enter image description here