Excel VBA检查另一个单元格中是否包含单元格单词

时间:2015-12-13 13:41:34

标签: vba excel-vba excel

我想检查一个单元格的所有单词是否包含在另一个单元格的子单词中。

例如:

enter image description here

B1中包含A1,但B1中不包含A2。

1 个答案:

答案 0 :(得分:3)

以下 UDF()将确定单元格中的所有单词是否出现在单元格中:

Public Function AreIn(Little As String, Big As String) As Boolean
   Dim good As Boolean, aLittle, aBig, L, B

   AreIn = False
   aLittle = Split(LCase(Little), " ")
   aBig = Split(LCase(Big), " ")

   For Each L In aLittle
      good = False
      For Each B In aBig
         If L = B Then
            good = True
         End If
      Next B
      If good = False Then Exit Function
   Next L
   AreIn = True
End Function

此处" word" 是一组不包含空格的字符。该测试不区分大小写。例如:

enter image description here