+ Reply to Thread
Results 1 to 8 of 8

Search function, for specific text, but need to match if it starts with

  1. #1
    Registered User
    Join Date
    03-23-2013
    Location
    seattle
    MS-Off Ver
    Excel 2007
    Posts
    36

    Search function, for specific text, but need to match if it starts with

    Please help.

    Have formula here that searching for string text, but need it to search only if it starts with that text and not anywhere where else.

    Here is the formula:
    IF(ISERROR(SEARCH("AMP",A4)),"",A4)

    Its working, but need it to look only if it starts with "AMP".

    Thanks!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Search function, for specific text, but need to match if it starts with

    Maybe:

    =IF(LEFT(A4,LEN("AMP"))="AMP",A4,"")


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Search function, for specific text, but need to match if it starts with

    You could also use COUNTIF with a wildcard, e.g.

    =IF(COUNTIF(A4,"Amp*"),A4,"")

    Note: that isn't case-sensitive - does it need to be? This version is case-sensitive

    =IF(EXACT(LEFT(A4,3),"AMP"),A4,"")
    Last edited by daddylonglegs; 05-05-2013 at 12:37 PM.
    Audere est facere

  4. #4
    Registered User
    Join Date
    03-23-2013
    Location
    seattle
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Search function, for specific text, but need to match if it starts with

    Thanks for the great help here... I'm moving forward!

    So, here is what I'm doing.

    First, I need to clean data so it does start with "AMP", so for that I use following:

    RIGHT(A4,LEN(A4)-4) - This gives me most of the data that starts with AMP

    Now, I want to display data that starts with AMP, so,

    =IF(COUNTIF(A4,"Amp*"),A4,"") - works great (don't need it to be case sensitive

    Now, how do I combine both formulas into one?

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Search function, for specific text, but need to match if it starts with

    So "AMP" is actually characters 5, 6 and 7 in your original data? Try this formula

    =IF(COUNTIF(A4,"????Amp*"),A4,"")

  6. #6
    Registered User
    Join Date
    03-23-2013
    Location
    seattle
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Search function, for specific text, but need to match if it starts with

    It works, but I still need to clean it up and remove first 4 characters, that is why I was using: RIGHT(A4,LEN(A4)-4)

    So, now need to combin either one of your formulas

  7. #7
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Search function, for specific text, but need to match if it starts with

    OK, I'd use REPLACE to remove the first 4 characters so that would be

    =IF(COUNTIF(A4,"????Amp*"),REPLACE(A4,1,4,""),"")

    or you could use MID like this

    =IF(MID(A4,5,3)="Amp",REPLACE(A4,1,4,""),"")

  8. #8
    Registered User
    Join Date
    03-23-2013
    Location
    seattle
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Search function, for specific text, but need to match if it starts with

    It worked! Thank you for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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