IF the first word of one cell is found within the contents of another...return value A

jeffcoleky

Active Member
Joined
May 24, 2011
Messages
274
Code:
=IF(A2="","EMPTY",(IF(ISNUMBER(SEARCH(A2,B2)),"Match","No-Match")))

I currently use the above formula to find out if the contents of cell A2 are included in the cell B2. It works well when there is only 1 word in A2. When there is more than one, it tries to match the entire cell and I need it to only match the 1st.

How do I change this to search for only the FIRST word of A2 in cell B2, and return "Match" if it is found, and "No-Match" if not?

Your help is much appreciated.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Does this work:
Code:
=IF(LEN(A2)<1,"EMPTY",(IF(ISNUMBER(SEARCH(LEFT(A2,FIND(" ",A2)-1),B2)),"Match","No-Match")))
 
Upvote 0
JackDanIce, I tried out formula with "ddd" in A and B - it says "No-Match".
 
Upvote 0
Good spot Sektor

My formula only works if A2 contains more than one word, seperated by a space. Otherwise, you'll need to build in an additional test for when A2 only contains a single word (or a revision of the formula itself)
 
Upvote 0
Does this work:
Code:
=IF(LEN(A2)<1,"EMPTY",(IF(ISNUMBER(SEARCH(LEFT(A2,FIND(" ",A2)-1),B2)),"Match","No-Match")))

No, it doesn't for some reason. I wish I could tell you on which types of data it works which others don't, but i can't seem to see a pattern to give you.

Here's some sample data to use. Obviously the code changes slightly in this example. I would want to test to see if the FIRST WORD of Cell B2 is or is not included in cell D2.

<style type="text/css">
table.tableizer-table {border: 1px solid #CCC; font-family: Arial, Helvetica, sans-serif; font-size: 12px;} .tableizer-table td {padding: 4px; margin: 3px; border: 1px solid #ccc;}
.tableizer-table th {background-color: #104E8B; color: #FFF; font-weight: bold;}
</style>

<table class="tableizer-table">
<tr class="tableizer-firstrow"><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th></tr> <tr><td>1</td><td>First</td><td>Last</td><td>Parties</td><td>Match?</td></tr> <tr><td>2</td><td>Terry & Julia</td><td>Jones</td><td>JONES, TERRY, J; JONES, JULIA, A</td><td>No-Match</td></tr> <tr><td>3</td><td>Robert & Brenda</td><td>Smith</td><td>SMITH, BRENDA; SMITH, BRENDA, B; SMITH, ROBERT, G; METRO GOVERNMENT; CAPITAL SOURCE BANK; AEON FINANCIAL LLC</td><td>No-Match</td></tr> <tr><td>4</td><td>Barry</td><td>James</td><td>JAMES, BARRY, L; SEARS ROEBUCK & CO</td><td>Match</td></tr> <tr><td>5</td><td>Jacqueline Ebert & Shearice Ellis</td><td> </td><td>ELLIS, SHEARICE, E; EBERT, JACQUELINE; ELLIS, GERALD; YOUR COUNTY FEDERAL CREDI, T UNION</td><td>No-Match</td></tr> <tr><td>6</td><td>Rodney & Antonya</td><td>Daisey</td><td>DAISEY, RODNEY, T; DAISEY, ANTONYA, A; COUNTY ME, TRO GOVERNMENT</td><td>No-Match</td></tr> <tr><td>7</td><td>Toni</td><td>Young</td><td>YOUNG, TONI, S; YOUNG, TONI</td><td>Match</td></tr></table>
 
Upvote 0
=IF(ISERR(FIND(UPPER(IF(ISERR(LEFT(B2,FIND(" ",B2))),B2LEFT(B2FIND(" ",B2))),UPPER(D2)),"No-Match","Match")

checks position of first space in b2, if no space returns the whole of b2 compares with d2
 
Upvote 0
Code:
=IF(A2="","EMPTY",(IF(ISNUMBER(SEARCH(A2,B2)),"Match","No-Match")))

I currently use the above formula to find out if the contents of cell A2 are included in the cell B2. It works well when there is only 1 word in A2. When there is more than one, it tries to match the entire cell and I need it to only match the 1st.

How do I change this to search for only the FIRST word of A2 in cell B2, and return "Match" if it is found, and "No-Match" if not?

Your help is much appreciated.
Try this...

=IF(A2="","Empty",IF(COUNT(SEARCH(LEFT(A2,FIND(" ",A2&" ")-1),B2)),"Match","No Match"))
 
Upvote 0
=IF(A2="","Empty",IF(COUNT(SEARCH(LEFT(A2,FIND(" ",A2&" ")-1),B2)),"Match","No Match"))

That one worked as far as i can tell! thanks T. Valko

(charleschuckiecharles & JackDanIce, thanks for trying too)
 
Upvote 0
=IF(A2="","Empty",IF(COUNT(SEARCH(LEFT(A2,FIND(" ",A2&" ")-1),B2)),"Match","No Match"))

That one worked as far as i can tell! thanks T. Valko

(charleschuckiecharles & JackDanIce, thanks for trying too)



Not to put another question within this post, but would be easy to change this formula to search cell B2 for ANY word in cell A2, rather than just the first word of A2?
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

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