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)
 
I wouldn't use ISERROR, but here is your macro without a loop and without selecting anything.

Code:
Sub ifforall()
With Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row)
    .Formula = "=IF(ISERROR(SEARCH(""EDM"",A2)),""ANOTHER NUMBER"", ""EDM"")"
    .Value = .Value
End With
End Sub
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Yes you're right but I only posted what he wished that can be easily understood.

well, your code will serve him better..

:) cheers!

-e.rgabrieldoronila
 
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


Nice formula. How would do this in vba using Search to get same results as your gem formula?

Biz
 
Upvote 0
Concept only:
Code:
Dim return As Long
Dim value As String
With Range
    Select Case cell.value
        Case "EDM"
            ...code here
            value = cell.Value
        Case "EDM2"
            ...code here
            value = cell.Value
        Case Else
            return = CLng(cell.Value)
    End Select
End With
 
Last edited:
Upvote 0
=LOOKUP(REPT("z",255),CHOOSE({1,2},"ANOTHER VALUE",LOOKUP(1000,FIND($E$1:$E$10,A1),$E$1:$E$10)))

OK.

The first part REPT("z",255) will return the last text value from the array.
The {1,2} in the CHOOSE Formula will return 2 values to an array.
The first array contains "Another Value" and the second array contains all the results from the FIND statement which will be either #N/A or the value from E1:E10 (The Result Vector). If all the values return #N/A, then the only other Text Value is "ANOTHER VALUE" so this is what it will return.
The second lookup uses 1000 (a number greater than would possibly be returned from this problem, so will therefore return the last match from E1:E10 to the 2nd value of the array. We made "ANOTHER VALUE" first, so that if there was a 2nd value it would return this one instead.
 
Last edited:
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)))

Sheet1

*ABCDE
1234 EDM100*EDM*EDM
5678 ADP2*ADP*ADP
**ANOTHER VALUE*VAL3
512 XQ5*ANOTHER VALUE*VAL4
****VAL5
****VAL6
****VAL7
****VAL8
****VAL9
****VAL10

<tbody>
[TD="bgcolor: #cacaca, align: center"]1[/TD]

[TD="bgcolor: #cacaca, align: center"]2[/TD]

[TD="bgcolor: #cacaca, align: center"]3[/TD]

[TD="bgcolor: #cacaca, align: center"]4[/TD]

[TD="bgcolor: #cacaca, align: center"]5[/TD]

[TD="bgcolor: #cacaca, align: center"]6[/TD]

[TD="bgcolor: #cacaca, align: center"]7[/TD]

[TD="bgcolor: #cacaca, align: center"]8[/TD]

[TD="bgcolor: #cacaca, align: center"]9[/TD]

[TD="bgcolor: #cacaca, align: center"]10[/TD]

</tbody>

Spreadsheet Formulas
CellFormula
C1=LOOKUP(REPT("z",255),CHOOSE({1,2},"ANOTHER VALUE",LOOKUP(1000,FIND($E$1:$E$10,A1),$E$1:$E$10)))
C2=LOOKUP(REPT("z",255),CHOOSE({1,2},"ANOTHER VALUE",LOOKUP(1000,FIND($E$1:$E$10,A2),$E$1:$E$10)))
C3=LOOKUP(REPT("z",255),CHOOSE({1,2},"ANOTHER VALUE",LOOKUP(1000,FIND($E$1:$E$10,A3),$E$1:$E$10)))
C4=LOOKUP(REPT("z",255),CHOOSE({1,2},"ANOTHER VALUE",LOOKUP(1000,FIND($E$1:$E$10,A4),$E$1:$E$10)))

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
Would you mind explaining how this formula works? It does work great, I would just like to understand how?
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,693
Members
452,938
Latest member
babeneker

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