+ Reply to Thread
Results 1 to 5 of 5

Using a loop to add '0's in between two other numbers to reach 12 digits total

  1. #1
    Registered User
    Join Date
    03-03-2009
    Location
    Gainesville, FL
    MS-Off Ver
    Excel 2002 SP3
    Posts
    39

    Using a loop to add '0's in between two other numbers to reach 12 digits total

    I have a UPC list. Some are more than 12 digits, and some with less than 12 digits. I need to make sure there are 12 digits in each UPC.

    I know how to count using LEN, strip leading zeros of those UPCs that are >12 digits using RIGHT.

    What I need now is any number with less than 12 digits, such as 000123, add a 4 to the beginning (4000123) and fill in '0's in between the 4 and the short UPC number to make 12 digits, 400000000123. They vary from 1 to 13 digits.

    I guess I need a loop of some sort?

    Thanks in advance.
    Last edited by giallofever; 03-24-2009 at 05:21 PM. Reason: SOLVED

  2. #2
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Using a loop to add '0's in between two other numbers to reach 12 digits total

    Assuming your short UPC is in cell A1, use this formula in another cell:

    Please Login or Register  to view this content.
    Would you like to say thanks? Please click the: " Add Reputation" button, on the grey bar below the post.

  3. #3
    Registered User
    Join Date
    03-03-2009
    Location
    Gainesville, FL
    MS-Off Ver
    Excel 2002 SP3
    Posts
    39

    Re: Using a loop to add '0's in between two other numbers to reach 12 digits total

    Worked perfectly, thank you. Just by chance is there any way to combine this with =IF(ISERROR(VALUE($B3)),$A3,$B3) ?

    SOLVED: =CONCATENATE(4,REPT(0,11-LEN(A1)),A1)

    Thanks
    Last edited by giallofever; 03-25-2009 at 10:13 AM.

  4. #4
    Forum Expert ConneXionLost's Avatar
    Join Date
    03-11-2009
    Location
    Victoria, Canada
    MS-Off Ver
    2010
    Posts
    2,952

    Re: Using a loop to add '0's in between two other numbers to reach 12 digits total

    I don't know what you have in $A3 or $B3, but if I have to guess, I'd say:

    Please Login or Register  to view this content.
    Last edited by ConneXionLost; 03-24-2009 at 05:36 PM.

  5. #5
    Registered User
    Join Date
    03-03-2009
    Location
    Gainesville, FL
    MS-Off Ver
    Excel 2002 SP3
    Posts
    39

    Re: Using a loop to add '0's in between two other numbers to reach 12 digits total

    Thanks for your help on the CONCATENATE, REPT. Combining it with the ISERROR didn't work so I am going to start a new thread for that.

+ 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