Solved

# Search for text in a string

Posted on 2014-11-18
83 Views
Could an Expert provide the answer to this please. I need to search a string of text and find one of several words.

i.e. I need to find Jan or Feb or Mar or Apr

I have the below formula but cannot figure out how to expand this to look for all of the above.

=IF(ISERROR(SEARCH("Jan",A1)),"","Jan")

Thanks
0
Question by:Jagwarman
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 3
• 3
• +1

LVL 30

Expert Comment

ID: 40449198
Try this
=IFERROR(MID("JanFebMarApr",FIND(A1,"JanFebMarApr",1),3),"")

gowflow
0

Author Comment

ID: 40449202
Hi gowflow I get a blank in the cell and in the formula window #Value
0

LVL 50

Accepted Solution

Ingeborg Hawighorst (Microsoft MVP / EE MVE) earned 500 total points
ID: 40449212
Hello,

I'd keep it simple and just concatenate the four different searches.

=IF(ISERROR(SEARCH("Jan",A1)),"","Jan")&IF(ISERROR(SEARCH("Feb",A1)),"","Feb")&IF(ISERROR(SEARCH("Mar",A1)),"","Mar")&IF(ISERROR(SEARCH("Apr",A1)),"","Apr")

cheers, teylyn
0

Author Comment

ID: 40449217
Thanks teylyn that is brilliant.

I cant "accept" on this PC will do that later from home.
0

LVL 30

Expert Comment

ID: 40449222
Sorry small mistake from my part
=IF(A1<>"",IFERROR(MID("JanFebMarApr",SEARCH(A1,"JanFebMarApr",1),3),""),"")

gowflow
0

Author Comment

ID: 40449233
It's still the same gowflow but the solution from teylyn works for me but thanks for trying
0

LVL 30

Expert Comment

ID: 40449238
ok fine but I don't understand what is the problem now
gowflow
0

LVL 50

Expert Comment

ID: 40449244
gowflow, can you explain your approach? I think you are searching in the wrong direction. As I understand it, cell A1 has some text, and it may contain any one of the month names in question, among other text.  So Find() or Search() need to look in A1 for any of the values Jan, Feb, Mar, Apr, and if found, return the respective text string.

Your formula takes the value of A1 and tries to find it in the sting "JanFebMarApr" and then returns the respective text string. But if A1 contains only the text, we get the same result with

=A1

cheers, teylyn
0

LVL 30

Expert Comment

ID: 40449249
Teylyn
As always you are great. I totally missed the boat here !!! tks for clarifying and sorry for Jagwarman for having you frustrated with my off-solution !

gowflow
0

LVL 18

Expert Comment

ID: 40449450
For 12 months

=IFERROR(INDEX({"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},MATCH(A1,{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0)),"")

Kris
0

LVL 18

Expert Comment

ID: 40449451
0

LVL 18

Expert Comment

ID: 40449453
I midread the question earlier. Here is a revised one.

=IFERROR(LOOKUP(9.999E+307,SEARCH({"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},A1),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"}),"")

Kris
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Excel compare strings 6 54
excel 2013 keeps 4 30
move line without macro or copy/paste 6 45
Embed XL WS and Objects into a PPTX 8 34
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,â€¦
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, tâ€¦
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templaâ€¦
###### Suggested Courses
Course of the Month6 days, left to enroll