我是VBA編程新手,希望能有人幫助解決這個問題。我一直在閱讀其他一些帖子,但對我來說太複雜了,無法理解我的水平。比較Excel中兩個單元格內的文本VBA
我想比較Excel中的兩個單元格,並試圖匹配這兩個單元格中的單詞,看看是否有任何單詞匹配它們之間。 (see picture for reference)
我是VBA編程新手,希望能有人幫助解決這個問題。我一直在閱讀其他一些帖子,但對我來說太複雜了,無法理解我的水平。比較Excel中兩個單元格內的文本VBA
我想比較Excel中的兩個單元格,並試圖匹配這兩個單元格中的單詞,看看是否有任何單詞匹配它們之間。 (see picture for reference)
嘗試這個小UDF():
Public Function WhatsInCommon(A As String, B As String) As String
arya = Split(LCase(A), " ")
aryb = Split(LCase(B), " ")
WhatsInCommon = ""
For Each aa In arya
For Each bb In aryb
If aa = bb Then
If WhatsInCommon = "" Then
WhatsInCommon = aa
Else
WhatsInCommon = WhatsInCommon & "," & aa
End If
End If
Next bb
Next aa
End Function
例如:
注:
這個版本只會考慮的話多於兩個字符:是一串字符用空格
編輯#1封裝
Public Function WhatsInCommon(A As String, B As String) As String
arya = Split(LCase(A), " ")
aryb = Split(LCase(B), " ")
WhatsInCommon = ""
For Each aa In arya
If Len(aa) > 2 Then
For Each bb In aryb
If aa = bb Then
If WhatsInCommon = "" Then
WhatsInCommon = aa
Else
WhatsInCommon = WhatsInCommon & "," & aa
End If
End If
Next bb
End If
Next aa
End Function
請回顧[如何提問](http://stackoverflow.com/help/how-to-ask)在本網站上獲得最佳幫助。 –