Hi all, In cell K1 I have (AUS). In L1 I want it to return the word to the left of the first instance of (AUS) from Column A.
In this instance it is CAULFIELD.
Can anyone assist with the coding to do this? (The row may not always be 8)
Hi all, In cell K1 I have (AUS). In L1 I want it to return the word to the left of the first instance of (AUS) from Column A.
In this instance it is CAULFIELD.
Can anyone assist with the coding to do this? (The row may not always be 8)
Using your posted workbook
this regular formula finds the cell containing the K1 text and returns the text to the left of that text
Is that something you can work with?Please Login or Register to view this content.
Hi cmb,
Here's some VBA:
Please Login or Register to view this content.
If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)
You can't do one thing. XLAdept
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin
Yes Ron, great help many thanks
Here is a different mix of functions that will give the results that you are looking for. The key is identifying what you are wanting to match. In this case it is the contents of K1 which could appear anywhere within the text string in a cell. The "*"&K1&"*", used by Ron Coderre and myself finds anything before K1 followed by anything after in the cell's text string. Match("*"&K1&"*",A1:A15,0) will by itself give the row number where the text in K1 is found. The "A"& in front of the MATCH produces a cell reference in text form where this match is. The Indirect is used to return the contents of that cell reference. LEFT is used to extract the contents of the cell that has the text from K1. It looks for the ( and then returns everything left of the ( so a -1 is added to the end of the LEFT function near the end of the formula. TRIM just removes all unnecessary spaces.
It was tempting to use a space instead of the ( but if there were to be more than 1 space (two words), the result would probably not be what you wanted. As long as there is a ( only around the search term and not before, this should work.
Formula:Please Login or Register to view this content.
Last edited by newdoverman; 10-12-2014 at 04:50 PM.
<---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.Ron W
@both Ron's - will your formula also get the next occurrence as does my routine?
We can only work with the facts we've been given. In the example, there were no duplicate entries.
That being said...
If I'd offered a solution that could return multiple occurrences...somebody would have come along with something shorter, touting it's brevity.
Instead, I offered a solution that assumes there is only one occurrence...so of course... :|
The formulas will return the first instance. There was nothing to indicate that anything else was wanted.
Maybe this
=IFERROR(INDEX(LEFT($A$1:$A$13,FIND(" (",$A$1:$A$13)-1),SMALL(IF(ISNUMBER(SEARCH("*"&SUBSTITUTE(SUBSTITUTE(K$1,"(",""),")",""),$A$1:$A$13)),ROW($A$1:$A$13)),ROWS(B$1:B1))),"")
...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.
A B 1CHEPSTOW CAULFIELD 2FAIRYHOUSE (IRE) RANDWICK 3HEXHAM 4MUSSELBURGH 5NEWMARKET 6WOLVERHAMPTON (AW) 7YORK 8CAULFIELD (AUS) 9HAWERA (NZ) 10SAN ISIDRO (ARG) 11KEENELAND (USA) 12MAISONS-LAFFITTE (FR) 13RANDWICK (AUS
If you like my answer please click on * Add Reputation
Don't forget to mark threads as "Solved" if your problem has been resolved
"Nothing is so firmly believed as what we least know."
--Michel de Montaigne
@ Ron Coderre - what does the colon pipe signify? - I haven't seen it before
@ Ron W - If the formula were dragged down, it would keep returning the first occurrence n'est pas?
I think it is like the Mona Lisa....neither a smile nor a frown :/ (a crooked smile)
It's the face you make when you make a puzzling observation and you say: Hmmmm
Hmmmmm :| Crooked smile :/ Great thanks guys :\
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks