任何人都可以帮我使用excel公式来查看一个带有文本字符串的单元格是否与具有相同文本字符串但位置不同的其他单元格相同。
请参阅下面的示例:
单元格A1:apple orange grape
单元格A2:orange grape apple
我需要一个公式来检查A1
是否相同A2
感谢
答案 0 :(得分:3)
将附加的代码放入模块中,并将其作为函数从工作表中调用,例如
=sCompare(A1,A2)
<强> CODE 强>
Public Function sCompare(s1 As String, s2 As String) As Boolean
Dim vArr1, vArr2, lLoop As Long, lLoop2 As Long, bMatch As Boolean
vArr1 = Split(trim(s1), " ")
vArr2 = Split(trim(s2), " ")
If UBound(vArr1) <> UBound(vArr2) Then Exit Function
For lLoop = 0 To UBound(vArr1)
bMatch = False
For lLoop2 = 0 To UBound(vArr2)
If vArr1(lLoop) = vArr2(lLoop2) Then
bMatch = True
Exit For
End If
Next lLoop2
If bMatch = False Then Exit Function
Next lLoop
sCompare = True
End Function