+ Reply to Thread
Results 1 to 4 of 4

How can I ensure entries in a column are 16 chars long using spaces?

  1. #1
    Registered User
    Join Date
    07-24-2007
    Posts
    9

    How can I ensure entries in a column are 16 chars long using spaces?

    Hi

    Sorry for the confusing title.
    I'm not too sure what this will be called, so struggled explaining it, let alone looking for it

    I have a column with text in it. I need to set the length of each entry to say 16 chars, using only spaces after the word, to make up any missing.

    There are several columns I need like this, which I will then export out to a flat txt file to feed into another program.

    i.e.
    "qwerty"
    "supercool"
    needs to be

    "qwerty "
    "supercool "

    Any ideas?

    i have tried a few basic ideas, but when you copy them across you loose the spacing

  2. #2
    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
    Say your data in Col A starting at A1 then enter this in B1 and drag down

    =A1&REPT(" ",16-LEN(A1))
    Paste special values and then delete Col A

    VBA Noob
    _________________________________________


    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 !!!

  3. #3
    Registered User
    Join Date
    07-24-2007
    Posts
    9
    cheers
    (I only needed 15 not 16 chars)
    That does it, except for if you copy and paste more than one column into a notepad/textpad, it increase the number of spaces by 1, in all but the last coumn

    So you have to modify the forumlar so it reads

    Column 1 Column 2 Column 3
    =A1&REPT(" ",14-LEN(A1)) =B1&REPT(" ",14-LEN(B1)) =C1&REPT(" ",15-LEN(C1))

    So that gives the correct chars in each column

    Also even with this change to correct it, the space between column 1 and column 2 is large than a normal space, rather a double space.
    Last edited by compact; 10-18-2007 at 05:59 AM.

  4. #4
    Registered User
    Join Date
    07-24-2007
    Posts
    9
    Ok
    I have played a bit and now it works like this.

    =A1&REPT(" ",15-LEN(A1)) & B1&REPT(" ",15-LEN(B1)) & C1&REPT(" ",15-LEN(C1))

    So you get it all in one cell.
    Then copy and paste special Value onto 2nd sheet, then save to txt file.

    Cheers guys, seems to be working

+ 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