If Cell contains x, return x, if it contains y, return y, or if it contains z, return z.

torourke17

New Member
Joined
Jan 12, 2018
Messages
12
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have thousands of cells with text containing various descriptions. I'm trying to search the text and tell me if the description says x, y, or z and to return which one it says. The descriptions are all over the board, but contain certain key words that I need to categorize. Example Below:

Data:
Cell A1 - "President Services May '18"
Cell A2 - "Services - Vice President - June '17"
Cell A3 - "Services April '16 - Secretary"
Cell A4 - "President March '18"
Cell A5 - "Secretary Services - January '18"
Cell A6 - "Secretary Services - May '18"
Cell A7 - "Vice President Services -March '18"

Formula would tell me if the cell is President, Vice President, or Secretary.
Cell B1 - President
Cell B2 - Vice President
Cell B3 - Secretary
etc.
etc.
etc.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Code:
=IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=2,"Vice President",IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=1,"President","Secretary"))

* Assumes all cells in A contain President, Vice President, or Secretary (if there are any that don't contain at least one of those three, then use:
Code:
=IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=2,"Vice President",IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=1,"President",IF(COUNTIF(A1,"*Secretary*"),"Secretary","")))
 
Last edited:
Upvote 0
Hi,

Here's another way:


Book1
ABC
1President Services May '18President
2Services - Vice President - June '17Vice President
3Services April '16 - SecretarySecretary
4Staff Meeting May '18
5President March '18President
6Secretary Services - January '18Secretary
7Secretary Services - May '18Secretary
8Vice President Services -March '18Vice President
Sheet39
Cell Formulas
RangeFormula
C1=IF(ISNUMBER(SEARCH("Vice President",A1)),"Vice President",IF(ISNUMBER(SEARCH("President",A1)),"President",IF(ISNUMBER(SEARCH("Secretary",A1)),"Secretary","")))
 
Upvote 0
Code:
=IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=2,"Vice President",IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=1,"President","Secretary"))

* Assumes all cells in A contain President, Vice President, or Secretary (if there are any that don't contain at least one of those three, then use:
Code:
=IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=2,"Vice President",IF(COUNTIF(A1,"*President*")+COUNTIF(A1,"*Vice*")=1,"President",IF(COUNTIF(A1,"*Secretary*"),"Secretary","")))

Hi,

Both formulas will give incorrect results, as there's "vice" in "services".
 
Upvote 0
You are right. I didn't account for all the possibilities given in the example. :(

Here's a corrected one using the same format:

Code:
=IF(COUNTIF(A1,"*Vice President*")=1,"Vice President",IF(COUNTIF(A1,"*President*")=1,"President",IF(COUNTIF(A1,"*Secretary*"),"Secretary","")))
 
Upvote 0
Hi,

Here's another way:

ABC
President Services May '18President
Services - Vice President - June '17Vice President
Services April '16 - SecretarySecretary
Staff Meeting May '18
President March '18President
Secretary Services - January '18Secretary
Secretary Services - May '18Secretary
Vice President Services -March '18Vice President

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"][/TD]

</tbody>
Sheet39

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]C1[/TH]
[TD="align: left"]=IF(ISNUMBER(SEARCH("Vice President",A1)),"Vice President",IF(ISNUMBER(SEARCH("President",A1)),"President",IF(ISNUMBER(SEARCH("Secretary",A1)),"Secretary","")))[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

Thanks jtakw, This works perfect if there are handful of search values, but in my case I have a long list of search values in 100s, and the text fields in 1000s, What is the best way to deal this? Thank you
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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