1

谁能帮我用一个excel公式来查看一个带有文本字符串的单元格是否与具有相同文本字符串但位置/位置不同的其他单元格相同。

请看下面的例子:

单元格 A1:apple orange grape

单元格 A2:orange grape apple

我需要一个公式来检查是否A1相同A2

谢谢

4

1 回答 1

3

将附加的代码放在一个模块中,并从您的工作表中将其作为函数调用,例如
=sCompare(A1,A2)

代码

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
于 2012-11-02T04:10:53.640 回答