Excel匹配字母

时间:2017-08-16 08:01:02

标签: excel

我正试图在Excel中使用一种允许我说出

的方法

ABC-DEF DEF-ABC

相同

任何人都知道如何做到这一点?

4 个答案:

答案 0 :(得分:1)

了解如何提问: https://stackoverflow.com/help/how-to-ask

有时,但有时候,(特征是 manchmal aber nur manchmal )你可能会幸运地发布这样的问题得到回答:

Option Explicit

Public Sub TestMe()

    Debug.Print CompareMe("ABC-DEF", "DEF-ABC")
    Debug.Print CompareMe("ABC-DEF", "DEF-AAC")

End Sub

Public Function CompareMe(strCompareA As String, strCompareB As String, Optional strDelim = "-")

    Dim arrA    As Variant
    Dim arrB    As Variant

    arrA = Split(strCompareA, strDelim)
    arrB = Split(strCompareB, strDelim)

    CompareMe = (arrA(0) = arrB(1) And arrA(1) = arrB(0))

End Function

检查TestMe子,它会在控制台中打印结果。

此外,this is an interview algorithm question, asked by Google。这是一个通用的工作答案 - 反转整个字符串,然后按字分割并反转每个单词。这是如何使用VBA:

Option Explicit

Public Sub TestMe()

    Debug.Print strReverseOrder("ABC-DEF-GHI")
    Debug.Print strReverseOrder("ABC-DEF") = "DEF-ABC"

End Sub

Public Function strReverseOrder(strToReverse As String, Optional strDelim = "-")

    Dim strWorking          As String
    Dim arrWorking()        As String
    Dim lngCounter          As Long
    Dim strAnswer           As String

    strWorking = StrReverse(strToReverse)
    arrWorking = Split(strWorking, strDelim)

    For lngCounter = LBound(arrWorking) To UBound(arrWorking)
        strAnswer = IIf(lngCounter = LBound(arrWorking), vbNullString, strAnswer & strDelim) & StrReverse(arrWorking(lngCounter))
    Next lngCounter

    strReverseOrder = strAnswer

End Function

答案 1 :(得分:1)

enter image description here

这是公式

=IF(AND(RIGHT(A8,3)=LEFT(A9,3),LEFT(A8,3)=RIGHT(A9,3)),TRUE,FALSE)

答案 2 :(得分:0)

以下对我有用:

=IF(D2>H2,CONCATENATE(D2,"-",H2),CONCATENATE(H2,"-",D2))

答案 3 :(得分:-1)

假设A1这是B1=IF(A1="ABC-DEF","DEF-ABC",A1)。向下拖动以填写。