+ Reply to Thread
Results 1 to 8 of 8

IF Statement Based on Text Search

  1. #1
    Registered User
    Join Date
    07-27-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    12

    IF Statement Based on Text Search

    Hi all,

    I've just joined the forum in hope that someone might be able to help me with an issue. I have a load of numbers and some have a * followed by two digits. E.g.

    12345
    12322
    1234*05
    1223*01

    What I'm trying to do is split these into two columns using a formula so that one column (left hand) has the numbers up to the * and the other (right hand) has everything after the *. In cases where there is no * the number should be reported to the left hand column and the right hand column should be blank.

    I've been using the following formula:

    =IF(ISNUMBER(SEARCH("*",K2)),MID(K2,1,FIND("*",K2)-1),K2)

    Where column K is the one with the uncleaned number. This works fine for cases where there is an * in K but where there isn't I get a #VALUE returned. Does anyone have any idea how I can work around this so I get the original value back if there is no *?

    Any help would be much appreciated - thanks in advance.

    Regards

    HA

  2. #2
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: IF Statement Based on Text Search

    Try this instead

    =IF(ISNUMBER(SEARCH("*",K2&"*")),MID(K2,1,FIND("*",K2&"*")-1),K2)
    or even
    =MID(K2,1,FIND("*",K2&"*")-1)
    Last edited by ChemistB; 07-27-2011 at 11:12 AM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: IF Statement Based on Text Search

    just use text to columns delimited with * as delimiter
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Valued Forum Contributor
    Join Date
    05-23-2011
    Location
    Lahore PK
    MS-Off Ver
    Excel 2007, 2013
    Posts
    627

    Re: IF Statement Based on Text Search

    try it
    =IF(ISERROR(IF(ISNUMBER(SEARCH("*",K2)),MID(K2,1,FIND("*",K2)-1),K2))=TRUE,K2,IF(ISNUMBER(SEARCH("*",K2)),MID(K2,1,FIND("*",K2)-1),K2))
    Azam
    If you want to say Thank you to a member, click the reputation icon (Star) in the left bottom of the post.
    For prompt answer, be descriptive, concise, short, direct, and to-the-point.

  5. #5
    Registered User
    Join Date
    07-27-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: IF Statement Based on Text Search

    Hi Azam many thanks for the quick solution. Can I just ask two quick questions in reply:

    1) Why does the way I was doing it get a #VALUE?
    2) How can I apply the formula you produced to give me the digits after the *?

    Once again thanks for your help, it's much appreciated.

    HA

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: IF Statement Based on Text Search

    @ azam ali??? seems overworked that!
    in b1
    =IF(ISNUMBER(FIND("*",A1)),LEFT(A1,FIND("*",A1)-1),A1)
    in c1
    =IF(ISNUMBER(FIND("*",A1)),MID(A1,FIND("*",A1)+1,255),"")

  7. #7
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: IF Statement Based on Text Search

    =SEARCH("*",K2) will see the * as a wildcard and return 1. FIND("*",K2) works as you'd expect it to. Switch to FIND or you can put a tilda ~ in front of the * to indicate to Excel that you are actually using * as a character and not a wildcard.

    =IF(ISNUMBER(SEARCH("~*",K2)),MID(K2,1,FIND("*",K2)-1),K2)

  8. #8
    Registered User
    Join Date
    07-27-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: IF Statement Based on Text Search

    Many thanks to all who replied

+ 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