+ Reply to Thread
Results 1 to 15 of 15

Find text to the left of character

  1. #1
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Find text to the left of character

    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)
    Attached Files Attached Files

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find text to the left of character

    Using your posted workbook
    this regular formula finds the cell containing the K1 text and returns the text to the left of that text
    Please Login or Register  to view this content.
    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Find text to the left of character

    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

  4. #4
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Find text to the left of character

    Yes Ron, great help many thanks

  5. #5
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find text to the left of character

    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: copy to clipboard
    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

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Find text to the left of character

    @both Ron's - will your formula also get the next occurrence as does my routine?

  7. #7
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find text to the left of character

    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... :|

  8. #8
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find text to the left of character

    The formulas will return the first instance. There was nothing to indicate that anything else was wanted.

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Find text to the left of character

    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
    1
    CHEPSTOW CAULFIELD
    2
    FAIRYHOUSE (IRE) RANDWICK
    3
    HEXHAM
    4
    MUSSELBURGH
    5
    NEWMARKET
    6
    WOLVERHAMPTON (AW)
    7
    YORK
    8
    CAULFIELD (AUS)
    9
    HAWERA (NZ)
    10
    SAN ISIDRO (ARG)
    11
    KEENELAND (USA)
    12
    MAISONS-LAFFITTE (FR)
    13
    RANDWICK (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

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Find text to the left of character

    @ Ron Coderre - what does the colon pipe signify? - I haven't seen it before

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Find text to the left of character

    @ Ron W - If the formula were dragged down, it would keep returning the first occurrence n'est pas?

  12. #12
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find text to the left of character

    I think it is like the Mona Lisa....neither a smile nor a frown :/ (a crooked smile)

  13. #13
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Find text to the left of character

    Quote Originally Posted by xladept View Post
    @ Ron W - If the formula were dragged down, it would keep returning the first occurrence n'est pas?
    Of course, it wasn't intended to do anything else.

  14. #14
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Find text to the left of character

    It's the face you make when you make a puzzling observation and you say: Hmmmm

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Find text to the left of character

    Hmmmmm :| Crooked smile :/ Great thanks guys :\

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extract text to left of nth character
    By cmb80 in forum Excel General
    Replies: 3
    Last Post: 06-16-2014, 11:09 AM
  2. [SOLVED] Find text left or right of a specific character in a text string
    By Locopete99 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-14-2014, 05:55 AM
  3. Extract text left and right of character part 2
    By stuartm4h in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-01-2013, 07:12 AM
  4. [SOLVED] Extract text left and right of character
    By stuartm4h in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-12-2013, 07:32 AM
  5. Macro to find character and delete all text in cell after the character
    By SpencerRichman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2012, 06:08 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1