+ Reply to Thread
Results 1 to 13 of 13

Automatically put line break after certain number of Character in a line in Excel

  1. #1
    Registered User
    Join Date
    01-10-2012
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Automatically put line break after certain number of Character in a line in Excel

    I will thank you in advance for providing any valuable solution or advise regarding this issue.

    I have to some regular reports which has huge number of records - the problem is with text fields which has a lot of text - so I have to go through a painful process of formatting by manually doing line breaks (Alt+Enter) and then resize the row to make all the text fit and appear. It takes a few hours every time I do this and hate it. I was wondering if anyone know a quick solution to this issue or if a macro can do line breaks.

    I am not a programmer but I was wondering if there is a function or way to break text after say every 60 characters and put Char(10) which is ANSI code for ALT+Enter to do line breaks.

    Any piece of advise will be much appreciated.

    Thanks,

    Shoro

  2. #2
    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: Automatically put line break after certain number of Character in a line in Excel

    This will insert a break after the first 60 characters.

    =LEFT(A1,60)&CHAR(10)&RIGHT(A1,LEN(A1)-60)

    However, you have to set Wrap Text to make it display properly. Which brings me to my next point, which is that if you set all cells to Wrap Text in the first place then you don't have to mess around with a formula. Why would you need actual line break characters in the data?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    01-10-2012
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Automatically put line break after certain number of Character in a line in Excel

    Thanks for your reply, Jeff. I will try to see if it works. The reason I am trying to put line break is to be able to accomodate large chunks of text (detailed description field). In the reports that I create the one of the users requirement is for the text to appear for each record. So right now I manually put line breaks and resize the Excel Rows to fit in all the text - sometimes I have to merge the fields to accomodate. I will try and see if this formula works.
    Cheers!
    Shoro

  4. #4
    Registered User
    Join Date
    01-10-2012
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Automatically put line break after certain number of Character in a line in Excel

    Thanks Jeff - I tried it but it doesn't seem to work. Is there any other approach or way that could help?

  5. #5
    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: Automatically put line break after certain number of Character in a line in Excel

    It worked for me, not sure what else to suggest. Did you set Wrap Text?

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Automatically put line break after certain number of Character in a line in Excel

    To Attach a Workbook with good sample data:
    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit
    Ben Van Johnson

  7. #7
    Registered User
    Join Date
    01-10-2012
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Automatically put line break after certain number of Character in a line in Excel

    Thanks for your replies guys. I have attached a sample file perhaps that would clearly explain as to what I am trying to achieve.
    Cheers!
    Shoro
    Attached Files Attached Files

  8. #8
    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: Automatically put line break after certain number of Character in a line in Excel

    I think I can help if you tell me a little more about what you are doing with the text.

    The text is rather long, nearly 2000 characters, and my formula only handles the first 60-character chunk, so a formula solution isn't going to work well unless it's a very long formula that can insert up to 30-40 line breaks. This would be very straightforward to do with a macro and I could help with that but I hesitate to put any effort into a solution until I really understand the problem.

    After I change the formatting for column B, here is what I see. [shoro=line breaks.jpg] I am assuming you must see the same thing but maybe not--after seeing your sample I am at a complete loss to understand why you need to insert line breaks. Your desired solution isn't any different to work with than the original text. I don't see the benefit of having spent hours to manually produce the type of result you show in column C.

    What are you doing with the text after you reformat it that you can't do with it in its original state?

  9. #9
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Automatically put line break after certain number of Character in a line in Excel

    Here's a user defined function:
    Please Login or Register  to view this content.
    in a blank cell: "=BreakLine(ref,#), ref = the address of the cell with string to break (e.g. A2), # = a number indicating break positions (60, 100, ...)
    See cell D2 in the attachment
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-10-2012
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Automatically put line break after certain number of Character in a line in Excel

    Thanks Jeff. I am using Excel 2003 so part of the challenge is its limitation to show more than 1188 characters in a cell. Perhaps you may be using Office 2007 or later that's why the difference in text may not be obvious between A and C. I think Office 2007 can accommodate around 3000 characters in a cell. Anyway, thanks again for your help.

  11. #11
    Registered User
    Join Date
    01-10-2012
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Automatically put line break after certain number of Character in a line in Excel

    Thanks a lot Ben - your solution seems to be working fine. Must say awesome work!

  12. #12
    Registered User
    Join Date
    06-21-2016
    Location
    Stanley, NC
    MS-Off Ver
    2013
    Posts
    15

    Re: Automatically put line break after certain number of Character in a line in Excel

    I just read this interesting thread and it falls directly on a project I am working on. There is a different for my project. After the first 60 characters (lets say there is 120 characters in cell A1), I need for the following 60 to be moved to A2. But if there is pre existing data already in A2, I need for that data to be moved down. So to keep everything in the original order. I am sure this is a simple logic for you, but I could use the help.

    Thank you

    Crw

  13. #13
    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: Automatically put line break after certain number of Character in a line in Excel

    Welcome to the forum cwhitley! As a new member, please take the time to review our rules. There aren't many, and they are all important.

    Quote Originally Posted by cwhitley View Post
    There is a different [need] for my project.
    If your need is different, you need to post a new question.

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

+ 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