user3014233
user3014233

Reputation:

Excel VBA check if cell words contained in another cell

I want to check if all words of one cell contained in sub words of another cell.

For example:

enter image description here

A1 contained in B1, but A2 not contained in B1.

Upvotes: 0

Views: 110

Answers (1)

Gary's Student
Gary's Student

Reputation: 96753

The following UDF() will determine if all the words in cell Little appear in cell Big:

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

Here a "word" is a set of characters that do not include a space. The test is case-insensitive. Example:

enter image description here

Upvotes: 2

Related Questions