Excel – 显示缺less的值

我正在寻求一些帮助,我试图找出一种方法来从两个值中获取数据,并显示另一个框中的差异。

AB 1 The cat and dog | 2 The and dog | cat 3 cat and dog | the 4 the cat | and dog 

有任何想法吗?

使用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) 

在这里输入图像说明

使用VBA,你可以创build一个自定义函数,将被减数分解成一个数组,将被减数parsing成一个字典,并通过被减数组循环来移除被减数中的元素以返回差值。 希望有帮助

试试这个小的用户定义的function:

 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 

在这里输入图像说明