IF statement w/ find text w/in string

atown

New Member
Joined
May 31, 2011
Messages
8
Hey,

wondering if anyone can solve this for me- havent been able to find a really good solution to this answer yet. I am trying to utilize an IF statement that will find a value within a text string and if the value exists, then return that value, else return another number.
A1:
23994 AD EDM1

using the above example, if A1 contains the value "EDM" then return "EDM" else return (another value)
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hey,

wondering if anyone can solve this for me- havent been able to find a really good solution to this answer yet. I am trying to utilize an IF statement that will find a value within a text string and if the value exists, then return that value, else return another number.
A1:
23994 AD EDM1

using the above example, if A1 contains the value "EDM" then return "EDM" else return (another value)


=IF(ISNUMBER(SEARCH("EDM",A1)),"EDM","Another Number")
 
Upvote 0
thx a lot- if i had to do this search for multiple values within a column of data, i.e. look for like 10 different values and return that particular value if contained in a cell- is there an easier way to do that then make a rediculously long if/search statement?
 
Upvote 0
Yes, you would need to use a macro--which will take me an hour or so to write and troubleshoot... I'm in the learning process of writing code so hopefully an ExcelMVP can answer you.
 
Upvote 0
ah ok i was thinking macro also but wasn't sure if there was a way to do a vlookup or a index/match function without using vba
 
Upvote 0
Why would you need a macro?

Assuming your list in E1:E10

=LOOKUP(REPT("z",255),CHOOSE({1,2},"ANOTHER VALUE",LOOKUP(1000,FIND($E$1:$E$10,A1),$E$1:$E$10)))

Excel Workbook
ABCDE
11234 EDM100EDMEDM
25678 ADP2ADPADP
3ANOTHER VALUEVAL3
4512 XQ5ANOTHER VALUEVAL4
5VAL5
6VAL6
7VAL7
8VAL8
9VAL9
10VAL10
Sheet1
 
Upvote 0
This is the formula

=IF(ISERROR(SEARCH("EDM",AG3827)),"ANOTHER NUMBER", "EDM")

and if you're looking for a macro, please try this and let me know if it works..

Assuming your data starts at Cell A2

Create a module and copy the code below.

Code:
Sub ifforall()
Range("A2").Select
Do Until IsEmpty(ActiveCell.Value)
ActiveCell.Offset(0, 1).FormulaR1C1 = "=IF(ISERROR(SEARCH(""EDM"",RC[-1])),""ANOTHER NUMBER"", ""EDM"")"
ActiveCell.Offset(0, 1).Value = ActiveCell.Offset(0, 1).Value
ActiveCell.Offset(1, 0).Select
Loop
End Sub

It will look for cells with values under column a (starting from cell A2), write the formula beside them, and rewrite them as values. It will loop until the next line (of course, going down) is empty.

:) cheers!

-e.rgabrieldoronila
 
Upvote 0
The op is looking for a whole range of values in each cell. But your macro could be done without a loop, and you rarely need to select cells in order to work with them. You can work with ranges directly in VBA.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,672
Members
452,937
Latest member
Bhg1984

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