+ Reply to Thread
Results 1 to 4 of 4

Add Leading Spaces to Alphanumeric field

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    Fort Worth, TX
    MS-Off Ver
    Excel 2007
    Posts
    30

    Add Leading Spaces to Alphanumeric field

    I would like to add leading spaces to an alphanumeric field in order to keep the field 5 characters. I did post a question very similar to this yesterday, the difference is a different data source. This example does not contain leading zeros like yesterdays post did. I can't put expected output below as the mail will left justify if I show leading spaces. For example 45K would contain 2 leading spaces.

    Data:
    45K
    118C
    7A
    36AN

    Thank you!

  2. #2
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Add Leading Spaces to Alphanumeric field

    Ie data at A1

    the formula
    =REPT("0";5-LEN(A1))&A1

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Add Leading Spaces to Alphanumeric field

    I know of no way to format a text string within the cell to display with left padding, but this formula will do it for you in another column. If your data starts in A1, enter this in the desired column and copy down:

    =REPT(" ",5-LEN(A1))&A1

    You will get an error if the cell has more than 5 characters to start with.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    09-12-2012
    Location
    Fort Worth, TX
    MS-Off Ver
    Excel 2007
    Posts
    30

    Re: Add Leading Spaces to Alphanumeric field

    The formula from 6StringJazzer worked fine after I did a trim on the entire column. 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