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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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
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

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet39

Worksheet Formulas
CellFormula
C1=IF(ISNUMBER(SEARCH("Vice President",A1)),"Vice President",IF(ISNUMBER(SEARCH("President",A1)),"President",IF(ISNUMBER(SEARCH("Secretary",A1)),"Secretary","")))

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

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,215,772
Messages
6,126,806
Members
449,337
Latest member
BBV123

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