+ Reply to Thread
Results 1 to 3 of 3

right align columns

  1. #1
    Registered User
    Join Date
    10-27-2006
    Posts
    9

    right align columns

    Hello again!

    Here is my problem: I want to import data from a txt file in to excel. The data is various sentences with numbers. I import the data by defining "space" as the column seperator (each word gets its own column). The length of the sentences is variable, but I am particularly interested in the last two or three words / numbers in each of these sentences. Is there a way that excel can "right align" the data? I don't care if it is by a mathematical equation or a macro or maybe I am overlooking a simple button. I'm using Excel XP or 2003.
    Thanks for any help in advance
    stermann

    p.s: For clarification here is a example of what I can not do on my own:

    Before

    Please Login or Register  to view this content.
    After

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064
    Try this:

    1) First, you need to find the text with the most spaces in it. Let's call this value 'x'. Load the data into a spreadsheet as it is.

    2) Insert a column so data is in column B

    3) In A1, enter
    =LEN(B1)-LEN(SUBSTITUTE(SUBSTITUTE(B1," ","")," ",""))

    4) Copy this value down column A
    Column A now contains the number of spaces in each text string

    5) Sort column A in reverse order and make a note of the contents of A1. This is the text with the most spaces in it. Call this value 'x'.

    6) Undo the sort so everything is back in its original order.

    7) Enter this formula in C1 and copy it all the way down Column C

    =REPT(" ",x-A1)

    Remember 'x' is the value that was in A1 and represents the maximum spaces in a line of text. So in step 5) if the value in A1 was 9 you'd enter
    =REPT(" ",9-A1) above

    8) In D1 enter and copy this formula down column D

    =C1&B1

    Youve now padded out each text line with extra spaces so each text line now contains the same number of spaces or words.

    9) Copy Column D

    10) Paste Special - Values, back to column D

    11) Select Column D

    12) Use Data - Text To Columns - Delimited
    Click space and make sure "Treat Consecutive Delimiters As One" is unticked

    You should now have right justified columns in Columns D, E, F etc

    So just delete the columns A, B, C

    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Registered User
    Join Date
    10-27-2006
    Posts
    9
    What else can I say but

    THANK YOU!

    Works like a charm.. I'd never have thought of solving my problem that way!
    Thanks again!

    stermann

+ 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