+ Reply to Thread
Results 1 to 6 of 6

Delete first character if it is 0

  1. #1
    Registered User
    Join Date
    06-28-2012
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2011
    Posts
    9

    Delete first character if it is 0

    I need a formula that removes the 0 from the beginning of this cell anytime it is 0. This needs to be used in conjunction with my formula to extract the data before the first _. For example:

    066131_3Q12_F_24C2_D.tif

    I need to extract 066131 but then automatically delete the 0.

    391761_3Q12_F_24E2_D.tif

    In this example I would just extract the 391761.

    I'm currently using this formula to do the extraction: =MID(E2,1,FIND("_",E2,1)-1)

    Thanks!

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

    Re: Delete first character if it is 0

    =IF(LEFT(E2,1)="0",MID(E2,2,FIND("_",E2,1)-2, MID(E2,1,FIND("_",E2,1)-1))
    Does that work for you?
    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
    Registered User
    Join Date
    06-28-2012
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2011
    Posts
    9

    Re: Delete first character if it is 0

    For some reason it says I have too many arguments in the formula.

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

    Re: Delete first character if it is 0

    Oops, forgot a )

    Try this
    =IF(LEFT(E2,1)="0",MID(E2,2,FIND("_",E2,1)-2), MID(E2,1,FIND("_",E2,1)-1))

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

    Re: Delete first character if it is 0

    =MID(E2,1,FIND("_",E2,1)-1)+0
    is another option if its always a number ,mind you that would strip of all leading zeros
    Last edited by martindwilson; 07-11-2012 at 04:41 PM.
    "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

  6. #6
    Registered User
    Join Date
    06-28-2012
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2011
    Posts
    9

    Re: Delete first character if it is 0

    Perfect!!! Both options worked great and your second option (deleting all leading zeros) solved a problem I didn't even think about. Thank you!

+ 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