VBA检查A是否适合B,但

时间:2018-08-22 14:10:31

标签: excel vba excel-vba

我不确定如何解释,所以我只给你一个例子。

我有一些字符串,例如:123?56?表示任何字符)。我想检查一个字符串是否适合另一个字符串。

示例:

  • 123456适合123?56
  • 123B56也适合123?56

您了解了原理。

现在,实际上还有更长的字符串,更像1234?9ZZ9???72?,而我想做的是检查我拥有所有数据的列中是否存在其他字符串,该字符串是否适合同一列中的任何其他字符串列。

理想情况下,它将返回每组“相同的数字”,但是我有信心做到这一点。我只是不知道如何处理?字符。

大小很少超过4-10K行。

1 个答案:

答案 0 :(得分:0)

下面是一些非常简单的代码,可以帮助您入门:

Sub CheckStrings()

    Dim string1 As String
    Dim string2 As String
    Dim string3 As String
    Dim string4 As String        

    string1 = "123?56"
    string2 = "123456"
    string3 = "123B56"
    string4 = "notamatch"

    If string2 Like string1 Then
        Cells(1, 1) = "Match"
    Else
        Cells(1, 1) = "No Match"
    End If

    If string3 Like string1 Then
        Cells(1, 2) = "Match"
    Else
        Cells(1, 2) = "No Match"
    End If

    If string4 Like string1 Then
        Cells(1, 3) = "Match"
    Else
        Cells(1, 3) = "No Match"
    End If

End Sub

当我运行该命令时,它将Match Match No Match放在当前工作表的上角。希望这足以适应适当的解决方案?

相关问题