Advanced Conditional Formatting: If Any Word GREATER than 1 Character in a cell, can be found within another cell.

jeffcoleky

Active Member
Joined
May 24, 2011
Messages
274
I can't wrap my brain around this scenario to come up with something.

Spelled out this is what I would like conditional formatting to do: Highlight a row if ANY word in A2 greater than 1 character, can be found within cell B2.

Why we need it:
We're trying to quickly identify which names in Columns A & B don't match up, that's all.


  • The reason we want any word 2 characters or more, is because we don't want to match middle initials.
  • The reason we are OK with matchin ANY word in column "A" and not just the first or last names is because if the person was married, divorced, etc. then their last name could be different (eg. Pat Smith -> Pat Jones) but they're still the same person. If they go by a shortened name (Patrick -> Pat) in one column and not the other, then we still want it to match. This won't be an exact science though because if a female divorces and goes by a shortened first name AND changes her last name, it won't find her (EG. Patricia Smith -> Pat Jones), but that's OK.

Does this make sense?

Here is my sample data:

Excel 2010
ABC
1Seaches These wordsWithin Same Row of this ColumnExists (Manual Result)
2PAT SMITHPATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCYes
3PAT JONESPATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCNo
4PATRICIA SMITHPATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCYes
5PATRICIA JONESPATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCYes
6BOB & SARA SMITHSMITHIE, BOBBIE; SMITHIE, JANETNo
7GUELDA tommyGUELDA, TOMMYYes
8MMCCI LLCTORSTRICK, SAMUEL; TORSTRICK, SAMUEL, W; MMCCI LLCYes
9WITTMER Chris J & Sandy JWITTMER, CHRIS, J; WITTMER, SANDY, J; FRANKFORT FRANKLIN COUNTY ME, TRO GOVERNMENTYes
10DOWNIE TONIDOWNIE, TONI; DESOKY, JOE, H; NATIONAL CHECK BUREAU INC; SOUTHERN EMERGENCY MEDICAL SPE, CIALISTS; FAYETTE COUNTY ME, TRO DEPARTMENT OF CO, DES & REGULATIONSYes
11TERRA JONESEDDINGTON, CHRISTIE; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK KENTUCKY; TERRA FUNDING INC; TERRA FUNDING LLC; COUNTY INVESTMENTS LLCYes
12JEFF TATESTRANGE, JAMES; POORE, JAN; JOE PROPERTIES LLC; SMW LOCAL 110 FEDERAL CREDIT U, NION; HANNIN, GREG, TATE; HANNIN, TATE; SHEFFIELD, DONYes
13HAMPTON Jeff L IIHAMPTON, JEFF, L II; HAMPTON, JEFF; HAMPTON, JEFF, II; CAPITAL ONE BANK USA NA; ECLIPSE BANK INC; FRANKFORT FRANKLIN COUNTY ME, TRO DEPARTMENT OF CO, DES & REGULATIONSYes
14BATTS JanetMASON, JANET; MASON, TONY; MY HEALTHCARE INC; COMMONWEALTH OF INDIANA WORKF, ORCE DEVELOPMENT CAB, INET EX REL DIVISION; FIRST UNION NATIONAL BANK OF N, ORTH CAROLINA; WACHOVIA BANK OF DELAWARE NATI, ONAL ASSN; CHRYSLER FINANCIAL; TD AUTO FINANCE LLCYes
15BRADEN LESLEY MaryBRADEN, LESLEY, MARY; FRANKFORT FRANKLIN COUNTY ME, TRO GOVERNMENTYes
16WILLIAM & ALEXANDRA CRUMS LAND TRUSTSMITH, SHANNON; SMITH, TARISA, LYNETTE FULLER; FULLER, TARISANo

<tbody>
</tbody>
Sheet1

Formatting Constants:

  • The words in Column "A" are ALWAYS separated by spaces or an "&". Never a comma or semicolon
  • The words in Column "B" are ALWAYS separated by a comma or a space. Each name is always separated by a semicolon ";".

I've tried all the ISNUMBER, SEARCH, and FIND variations I can think of... but what I need is more complicated than I can figure out. I'm sure what i need is a complex version of the below formulas:
=ISNUMBER(SEARCH(A2,B2))
=ISNUMBER(FIND(A2,B2))

I'm OK adding a macro or a column to the sheet if needed.

I know how to set the conditional formatting rule up, I just need help with the formula. Anyone?
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi,

I'm not sure you're sample output matches your description because for example:
-> In row 3, there is a partial match for PAT
-> In row 6, there are partial matches for BOB and SMITH

If your happy adding extra columns, one option you can try is to:
-> Use Text to Columns to split out the entries in column A using a single space as a delimeter
-> Apply one of the following formulas

Method 1 - allowing for partial matches (using CTRL-SHIFT-ENTER rather than just ENTER as this is an array formula):
Code:
=ISNUMBER(
    LOOKUP(
      9.99999999999999E+307,
      IF(LEN(D2:I2) > 1, SEARCH(D2:I2, A2))))

Method 2 - not allowing for partial matches, but returns the results shown in your sample output (also requires CTRL-SHIFT-ENTER):
Code:
=ISNUMBER(
    LOOKUP(
      9.99999999999999E+307,
      IF(
        LEN(D2:I2) > 1,
        SEARCH(
          "|" & D2:I2 & "|",
          "|" & SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2, " ", "|"), ",", ""), ";", "") & "|"))))

Here is the sample output from both methods (note I have moved the split data from column A to columns D:I):

Excel 2013
ABCDEFGHI
1Within Same Row of this ColumnExists (Method 1)Exists (Method 2)Seaches These words
2PATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCTRUETRUEPATSMITH
3PATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCTRUEFALSEPATJONES
4PATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCTRUETRUEPATRICIASMITH
5PATRICIA SMITH; EDDINGTON, BETSY; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK INDIANA; TERRAS FUNDING INC; TERRAS FUNDING LLC; COUNTY LINE INVESTMENTS LLCTRUETRUEPATRICIAJONES
6SMITHIE, BOBBIE; SMITHIE, JANETTRUEFALSEBOB&SARASMITH
7GUELDA, TOMMYTRUETRUEGUELDAtommy
8TORSTRICK, SAMUEL; TORSTRICK, SAMUEL, W; MMCCI LLCTRUETRUEMMCCILLC
9WITTMER, CHRIS, J; WITTMER, SANDY, J; FRANKFORT FRANKLIN COUNTY ME, TRO GOVERNMENTTRUETRUEWITTMERChrisJ&SandyJ
10DOWNIE, TONI; DESOKY, JOE, H; NATIONAL CHECK BUREAU INC; SOUTHERN EMERGENCY MEDICAL SPE, CIALISTS; FAYETTE COUNTY ME, TRO DEPARTMENT OF CO, DES & REGULATIONSTRUETRUEDOWNIETONI
11EDDINGTON, CHRISTIE; CAPITAL ONE BANK; AMERICAN GENERAL FINANCIAL SER, VICES INC; AMERICAN GENERAL FINANCE; SEARS ROEBUCK & CO; NATIONAL CITY BANK KENTUCKY; TERRA FUNDING INC; TERRA FUNDING LLC; COUNTY INVESTMENTS LLCTRUETRUETERRAJONES
12STRANGE, JAMES; POORE, JAN; JOE PROPERTIES LLC; SMW LOCAL 110 FEDERAL CREDIT U, NION; HANNIN, GREG, TATE; HANNIN, TATE; SHEFFIELD, DONTRUETRUEJEFFTATE
13HAMPTON, JEFF, L II; HAMPTON, JEFF; HAMPTON, JEFF, II; CAPITAL ONE BANK USA NA; ECLIPSE BANK INC; FRANKFORT FRANKLIN COUNTY ME, TRO DEPARTMENT OF CO, DES & REGULATIONSTRUETRUEHAMPTONJeffLII
14MASON, JANET; MASON, TONY; MY HEALTHCARE INC; COMMONWEALTH OF INDIANA WORKF, ORCE DEVELOPMENT CAB, INET EX REL DIVISION; FIRST UNION NATIONAL BANK OF N, ORTH CAROLINA; WACHOVIA BANK OF DELAWARE NATI, ONAL ASSN; CHRYSLER FINANCIAL; TD AUTO FINANCE LLCTRUETRUEBATTSJanet
15BRADEN, LESLEY, MARY; FRANKFORT FRANKLIN COUNTY ME, TRO GOVERNMENTTRUETRUEBRADENLESLEYMary
16SMITH, SHANNON; SMITH, TARISA, LYNETTE FULLER; FULLER, TARISAFALSEFALSEWILLIAM&ALEXANDRACRUMSLANDTRUST

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1
 
Upvote 0
Or maybe a UDF

Code:
Function FindString(str1 As String, str2 As String) As String
    Dim spl As Variant, bFound As Boolean, i As Long, strAux As String
    
    strAux = Replace(str2, ";", " ")
    strAux = Replace(strAux, ",", " ")
    spl = Split(str1, " ")
    
    For i = 0 To UBound(spl)
        If Len(spl(i)) > 1 And InStr(1, " " & strAux & " ", " " & spl(i) & " ", vbTextCompare) Then
            bFound = True
            Exit For
        End If
    Next i
        
    If bFound Then
        FindString = "Yes"
    Else
        FindString = "No"
    End If
        
        
End Function

Usage

C2
=FindString(A2,B2)

copy down

M.
 
Upvote 0
circledchicken: Partial matches are NOT ok. Pat in A could not show a positive match if PATRICIA was in B. That is why rows 3 & 6 are both no's. I'm OK adding ONE column, not multiple...unless I absolutely have to. Is there a cleaner way to do it?
 
Upvote 0
Or maybe a UDF

Code:
Function FindString(str1 As String, str2 As String) As String
    Dim spl As Variant, bFound As Boolean, i As Long, strAux As String
    
    strAux = Replace(str2, ";", " ")
    strAux = Replace(strAux, ",", " ")
    spl = Split(str1, " ")
    
    For i = 0 To UBound(spl)
        If Len(spl(i)) > 1 And InStr(1, " " & strAux & " ", " " & spl(i) & " ", vbTextCompare) Then
            bFound = True
            Exit For
        End If
    Next i
        
    If bFound Then
        FindString = "Yes"
    Else
        FindString = "No"
    End If
        
        
End Function

Usage

C2
=FindString(A2,B2)

copy down

M.

Edited code of sheet, pasted your function, used your formula, and i still get a "#NAME?" error... am i doing something wrong?
 
Upvote 0
circledchicken: Partial matches are NOT ok. Pat in A could not show a positive match if PATRICIA was in B. That is why rows 3 & 6 are both no's. I'm OK adding ONE column, not multiple...unless I absolutely have to. Is there a cleaner way to do it?
Marcelo's UDF in post #3 is the way to go then for a concise full match.

You need to put the code in a regular module (through Insert -> Module) rather than a Sheet module. See here for more detail:
http://www.contextures.com/xlvba01.html#Worksheet
 
Last edited:
Upvote 0
Wow, is it really that simple? It seems to work fine now that I added it properly. Thanks to you both.
 
Upvote 0
Another way (with formula):

Array formula - use Ctrl+Shift+Enter and not only Enter to enter the formula

Code:
In C2

=IF(COUNT(SEARCH(IF(LEN(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),(ROW($1:$999)-1)*LEN(A2)+1,LEN(A2))))>1,
" "&TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),(ROW($1:$999)-1)*LEN(A2)+1,LEN(A2)))&" ")," "&SUBSTITUTE(SUBSTITUTE(B2,";"," "),","," ")&" ")),"Yes","No")

Markmzz
 
Upvote 0

Forum statistics

Threads
1,215,515
Messages
6,125,279
Members
449,220
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top