簡體   English   中英

在excel中,如何比較單個單元格中的多個值

[英]In excel, How to compare multiple values in single cell

123,123,123
456,789,456,258,652

我在一個單元格中有 3 個值,在下一個單元格中有 5 個值,用逗號分隔。 我想比較 A1 中的所有值,如果它們都是唯一的,則結果應該是 True。 如果不是唯一的結果應該是假的。

預期輸出:

123,123,123 真的
456,789,456,258,652 錯誤的

如何在excel中做到這一點。 請給我一個想法。 提前致謝

這是使用 VBA 的一個簡單實現,但是使用公式也是可能的

Sub CheckIfSame()
    Dim counter As Integer
    'Dim arrSplitStrings1() As Variant
    counter = 2
    Do While True
        If Cells(counter, 1) <> "" Then
            Cells(counter, 2) = ElementsSame(Split(Cells(counter, 1), ","))
        Else
            Exit Do
        End If
       counter = counter + 1
    Loop

End Sub

Function ElementsSame(arr As Variant) As Boolean
    Dim l As Long
    ElementsSame = True
    For l = 1 To UBound(arr)
        If arr(0) <> arr(l) Then
            ElementsSame = False
            Exit For
        End If
    Next l
End Function

在此處輸入圖片說明

基於VAR.S() 函數Evaluate()解決方案。 如果所有數字都相等,則VAR.S()=0

Function IsEqual(txt As String)
    IsEqual = Evaluate("VAR.S(" & txt & ")") = 0
End Function

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM