+ Reply to Thread
Results 1 to 10 of 10

line spacing between sections?

  1. #1
    Registered User
    Join Date
    07-02-2015
    Location
    Lake George, CO
    MS-Off Ver
    office 13
    Posts
    6

    Cool line spacing between sections?

    Hello everyone, I have a text file that I generated from Excel. This text file has 1000 lines of random information. Here is the text file from Excel:

    MB416859 A 27
    EV428465 U 36
    JS218719 G 167
    OU690872 G 126

    This is what the text file needs to look like:

    AB112233 A 134
    EE555555 G 18
    OU690872 U 122

    Is there a way of formatting the cells so there is only one space between each section? I would not enjoy going through line by line and correcting it. I hope there is a way of doing it by columns. Thank you.

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: line spacing between sections?

    Can you clarify or post a sample workbook (with no confidential / private info) indicating before and after?

    They both look the same to me...

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: line spacing between sections?

    Hi, welcome to the forum

    MB416859 A 27
    EV428465 U 36
    JS218719 G 167
    OU690872 G 126

    This is what the text file needs to look like:

    AB112233 A 134
    EE555555 G 18
    OU690872 U 122
    Hopefully, those are 2 completely different sets of data, because I can see no comparison between them?

    Formatting does not change the cell contents, only it's appearance. If you have more than 1 space between your data, there are 2 ways I can think of...
    1. Use Find/Replace. Find "space" "space", replace with "space
    2. use a helper column with the TRIM() function. then copy/paste values back over your data, and delete the helper
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    07-02-2015
    Location
    Lake George, CO
    MS-Off Ver
    office 13
    Posts
    6

    Re: line spacing between sections?

    When I post my text file to the forum, it corrects it like the bottom example. For example, the first line looks like this:
    MB416859 <8spaces> A <8spaces> 27 and the rest of the lines follow the same suit, for all 1000 lines. I'm not sure how to correct this by highlighting the whole column and moving everything over. I can do it line by line but that would be a headache.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: line spacing between sections?

    Yes, the forum removes extra spaces when you copy here. (there are 4 spaces between these words)
    Thats why you were asked for a sample workbook

    Did you try the Find/Replace?

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: line spacing between sections?

    Quote Originally Posted by jpanther View Post
    Hello everyone, I have a text file that I generated from Excel. This text file has 1000 lines of random information. Here is the text file from Excel:

    MB416859 A 27
    EV428465 U 36
    JS218719 G 167
    OU690872 G 126

    This is what the text file needs to look like:

    AB112233 A 134
    EE555555 G 18
    OU690872 U 122

    Is there a way of formatting the cells so there is only one space between each section? I would not enjoy going through line by line and correcting it. I hope there is a way of doing it by columns. Thank you.
    You appear to want to remove spaces (and Tabs I think) between words even though this thread's title say "line spacing". Assuming that, this macro should operate directly on the text file without needing to copy any data to the worksheets first. Simply replace my example path/filenames (indicated in red) with the path/filename to your actual text file.
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 07-03-2015 at 05:35 PM.

  7. #7
    Registered User
    Join Date
    07-02-2015
    Location
    Lake George, CO
    MS-Off Ver
    office 13
    Posts
    6

    Re: line spacing between sections?

    I want just one space between the words when it is saved as a text file. I am able to remove all the tabs and spaces in Excel and make it all one big string, but then I'm not able to add a space between the words when I save it again as a text. Will the macro just take away the spacing ? I never worked with macros, where would I place this after I replace the file location? Thank you.

  8. #8
    Registered User
    Join Date
    07-02-2015
    Location
    Lake George, CO
    MS-Off Ver
    office 13
    Posts
    6

    Re: line spacing between sections?

    Thank you for your help. I can't locate the Find/Replace. Also your instructions say: Find "space" "space", replace with "space. How does that work?

  9. #9
    Registered User
    Join Date
    07-23-2014
    Location
    Rhode Island, USA
    MS-Off Ver
    2007
    Posts
    5

    Re: line spacing between sections?

    Find and replace is the simplest option. I have Excel 2011 for Mac, but the directions should be similar. Don't forget to back up the file.
    1. Open up your Excel file in Microsoft Excel
    2. On the toolbar at the top, click "Edit" -> "Replace" (or Find and Replace)
    3. Under "Find What", type in 8 spaces, nothing more. The field should appear blank, but it does have 8 spaces.
    4. Under "Replace", only put one space.
    5. Click "Replace All".

    This should do it, but if I am wrong feel free to correct me.

  10. #10
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: line spacing between sections?

    Quote Originally Posted by jpanther View Post
    Will the macro just take away the spacing ? I never worked with macros, where would I place this after I replace the file location?
    The macro will leave a single space between each word within each cell. I could not tell from the line before the one I quoted above whether your ultimate goal is to join each cell together so that everything is in one cell at the end or not. If that is what you want, I can change the macro to do that for you.


    Quote Originally Posted by jpanther View Post
    I never worked with macros, where would I place this after I replace the file location?
    See below for instructions. One note... as written, the code will physically replace the original file. If that is not what you want, change the file name in the second red section to some name other than the original file's name.


    HOW TO INSTALL MACROs
    ------------------------------------
    If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (MoveStatesUpOneRowInColumnF) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Line spacing within a cell
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2012, 06:42 PM
  2. adding colour to sections of a line graph
    By molemeister in forum Excel General
    Replies: 5
    Last Post: 10-18-2012, 04:42 PM
  3. [SOLVED] line spacing in cell
    By dlh in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 03-24-2006, 11:15 AM
  4. Legend Line Spacing
    By Bill Sturdevant in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 07-06-2005, 08:05 AM
  5. [SOLVED] Line Spacing & hyperlink - ajit
    By Ajit Munj in forum Excel General
    Replies: 3
    Last Post: 04-08-2005, 03:06 AM

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