position of the 1st element of an array found in a string

baucucu

New Member
Joined
Aug 3, 2007
Messages
5
Hi guys

Given the array {a,b,c,d,e} and the string "y x q z b a"
I need a formula that returns a or 1 as the first element in the array to be found in the string

Can you guys help?

Thanks
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi & Welcome to the Board!

Does the following work for you? It is an array formula that needs to be entered with Ctrl+Shift+Enter:

Excel Workbook
A
1y x q z b a
2
31
Sheet1
 
Upvote 0
Re: position of the 1st element of an array found in a strin

Code:
Sub test()
Dim myArray, myString As String, n As Long, msg
myArray = [{"a","b","c","d","e"}] 
myString = "y x q z b a"

For Each e In myArray
     If InStr(1, myString, e, 1)>0 Then
          msg = e
     End If
     n = n + 1
Next
MsgBox IIf(Len(msg)>0, msg & vbLf & n + 1, "Not Found")
End Sub
 
Upvote 0
Hi & Welcome to the Board!

Does the following work for you? It is an array formula that needs to be entered with Ctrl+Shift+Enter:

Excel Workbook
A
1y x q z b a
2
31
Sheet1

Thank you Richard,
Doesn't look to complicated so I guess I need to start learning more about array formulae
Yes, it solves my problem.

Alex
 
Upvote 0
Richard's suggested formula doesn't actually need CTRL+SHIFT+ENTER

...although it does if you replace the array constant with a range, i.e. something like this:

=MATCH(TRUE,ISNUMBER(FIND(B1:B5,A1)),0)
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,004
Members
449,480
Latest member
yesitisasport

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