+ Reply to Thread
Results 1 to 9 of 9

Leading zeroes in a text field

  1. #1
    Registered User
    Join Date
    02-06-2007
    Posts
    3

    Leading zeroes in a text field

    I have a situation where I have employee numbers ranging from 1 to 5 digits. I need to add leading zeroes to make the field nine digits total. (I can do this by using Format/Custom/and entering 9 zeroes.) At the same time, I need the field to be a text field, because I need to concatenate it with two other fields and retain the leading zeroes. Therefore, my spreadsheet will have four columns:
    Company Number = 0008, Employee Number = 000000001, Dist Number = 03, Concatenated field = 000800000000103. I can't figure out how to add the leading zeroes, but keep that field a text field, so it shows the zeroes in the concatenated field. Thanks in advance for any assistance!

  2. #2
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Try this,

    =TEXT(A1,"0000")&TEXT(B1,"000000000")&TEXT(C1,"00")
    oldchippy
    -------------


    Blessed are those who can give without remembering and take without forgetting

    If you are happy with the help you have received, please click the <--- STAR icon on the left - Thanks.

    Click here >>> Top Excel links for beginners to Experts

    Forum Rules >>>Please don't forget to read these

  3. #3
    Registered User
    Join Date
    02-06-2007
    Posts
    3

    Ending Spaces in a text field

    The formula for TEXT(etc.) worked! Thanks!

    Now I have another field I need to add to the mix with spaces at the end of a word. Therefore, my columns will be company = 8, employee number = 12345, action = PAYRATE, date = 20070315 with a concatenated field of company with three leading zeros, employee number with nine digits, action which is PAYRATE and should have three spaces at the end to create a field of 10 characters and a date in the format of yyyymmdd. So with the above values, my concatenated field should be 0008000012345PAYRATE 20070315. Thanks in advance for your assistance!!

  4. #4
    Registered User
    Join Date
    02-06-2007
    Posts
    3

    Ending spaces and concatenation

    I am trying to add leading zeroes to some fields and spaces to the end of one field and concatenate all of that into one field. I got an aswer on the leading zeroes piece, but now am adding the "spaces at the end of a word."

    Therefore, my columns will be company = 8, employee number = 12345, action = PAYRATE, date = 20070315 with a concatenated field of company with three leading zeros, employee number with nine digits, action which is PAYRATE and should have three spaces at the end to create a field of 10 characters and a date in the format of yyyymmdd. So with the above values, my concatenated field should be 0008000012345PAYRATE 20070315. Thanks in advance for your assistance!!

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    Try

    =REPT(0,4-LEN(A1))&A1&REPT(0,9-LEN(B1))&B1&C1&" "&D1

    or with date format

    =REPT(0,4-LEN(A1))&A1&REPT(0,9-LEN(B1))&B1&C1&" "&TEXT(D1,"yyyymmdd")

    VBA Noob
    Last edited by VBA Noob; 02-12-2007 at 05:58 PM.
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675
    If PAYRATE is in C1 and should always have 10 characters try

    =LEFT(C1&" ",10)

    [thats 10 spaces between the quotes]

    so in all you'd have

    TEXT(A1,"000")&TEXT(B1,"000000000")&LEFT(C1&" ",10)&TEXT(D1,"yyyymmdd")

  7. #7
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Try this, with your number in A1 and B1, text in C1 and date in D1 and this in E1

    =TEXT(A1,"0000")&TEXT(B1,"000000000")&C1&D1

    this will make A1 to be upto 4 numbers, B1 upto nine number, C1 (what ever length) and D1 (what ever length)

    Hope this helps.

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Why post twice ??

    VBA Noob

  9. #9
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Sorry didn't see yours, just logged straight in to User CP to see replies I'd had

+ 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