+ Reply to Thread
Results 1 to 12 of 12

Add zero if sum of two characters within a string is less than ten

  1. #1
    Registered User
    Join Date
    06-08-2013
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2010
    Posts
    4

    Add zero if sum of two characters within a string is less than ten

    Hi all.
    I am a new registrant and have the following question.
    I have a series of number strings such as:
    1 – 2 – 18 – 25 – 45 – 5 – 8 – 17 – 99 – and so on.
    Each number string is in a different cell (such as A1, A2, A3 and so on).
    I want to add a number zero at each instance where a character in a string is less than ten so that all numbers within each string will have two characters, for example:
    01 – 02 – 18 – 25 – 45 – 05 – 08 – 17 – 99
    Each string is a different cell. The largest two character number within each string is 99. I am using Excel 2010 and Explorer 10. Any suggestions?
    I will appreciate your responses.
    Thank you.
    Fred

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

    Re: Add zero if sum of two characters within a string is less than ten

    with those numbers are in a1,a2 so on in b1 put =TEXT(A1,"00") fill down
    alternatively you could format the cells using a custom format of 00
    "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

  3. #3
    Registered User
    Join Date
    06-08-2013
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Add zero if sum of two characters within a string is less than ten

    Thank you martindwilson.

    I did try using your suggestion (=TEXT(B1,"00") but this does not enter a zero before the characters 1 to 9 in the number strings. Any other suggestions?

    Fred

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Add zero if sum of two characters within a string is less than ten

    You added an ( to much on your formula.

    try again with the offered formula, and you will see it work for you.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  5. #5
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Add zero if sum of two characters within a string is less than ten

    Good morning!

    Would the following help?

    If your data starts from A1, type
    Please Login or Register  to view this content.
    Into Cell B1, then copy down for as many rows have data in A.

    Regards, Galvinpaddy

  6. #6
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Add zero if sum of two characters within a string is less than ten

    although Martindwilsons does work

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

    Re: Add zero if sum of two characters within a string is less than ten

    ahh do you mean a1 contains
    1 – 2 – 18 – 25 – 45 – 5 – 8 – 17 – 99
    a2 contains say
    1 – 3 – 18 – 30 – 45 – 41 – 8 – 9 – 88

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

    Re: Add zero if sum of two characters within a string is less than ten

    ahh do you mean a1 contains
    1 – 2 – 18 – 25 – 45 – 5 – 8 – 17 – 99
    a2 contains say
    1 – 3 – 18 – 30 – 45 – 41 – 8 – 9 – 88

  9. #9
    Valued Forum Contributor Melvinrobb's Avatar
    Join Date
    06-19-2012
    Location
    Manitoba, Canada
    MS-Off Ver
    Excel 2013
    Posts
    1,128

    Re: Need help adding zero each time the sum of two characters within a string is less than

    in B1 insert this formula and drag across. Then just "Copy - Paste Values"
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Please click the * icon below if I have helped.

  10. #10
    Registered User
    Join Date
    06-08-2013
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Need help adding zero each time the sum of two characters within a string is less than

    Thank you all.

    I tried your suggestions but none provides the solution I need.

    I also tried: ="0"&IF(LEFT(BF41,2)<"10",LEFT(BF41,3)&MID(BF41,4,100),LEFT(BF41,2)&MID(BF41,3,100))
    But this only inserts a zero at the beginning of each number string, not every time the sum of two characters is less than ten. For example, it converts:
    21 – 2 – 18 – 25 – 45 – 5 – 8 – 17 – 99

    Into:

    021 – 2 – 18 – 25 – 45 – 5 – 8 – 17 – 99

    Instead of:

    21 – 02 – 18 – 25 – 45 – 05 – 08 – 17 – 99

    Any suggestion will be greatly appreciated.

    Fred

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

    Re: Add zero if sum of two characters within a string is less than ten

    you will have to split and rejoin if you want to use a formula

  12. #12
    Forum Expert
    Join Date
    12-11-2011
    Location
    Netherlands
    MS-Off Ver
    office 365
    Posts
    3,289

    Re: Add zero if sum of two characters within a string is less than ten

    First: text to columns with delimiters other ' – '
    Second: check =if(len(a1)=1,"0"&a1,a1) for each cel
    Third: =A2&" – "&B2&" – "&C2&" – "&D2&" – "&E2&" – "&F2&" – "&G2&" – "&H2&" – "&I2
    Willem
    English is not my native language sorry for errors
    Please correct me if I'm completely wrong

+ 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