+ Reply to Thread
Results 1 to 11 of 11

VBA to insert line break (Alt+Enter)

  1. #1
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    VBA to insert line break (Alt+Enter)

    Hi all,

    Another query...

    I have cells set to character width of 40 with word wrap.

    I have approx 1000 cells with approx 100 words in each. This file is exported into another program which does not pick up the word wrapping. As such, I need a way to insert line breaks wherever each line ends in each cell.

    So basically. Rather than go through 10000 lines pressing Ctrl+Enter, I was hoping there is a quick way to achieve the same.

    A bit of VBA I could run that would force line breaks in all cells within column B would be ideal?

    As always. Any help appreciated!

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: VBA to insert line break (Alt+Enter)

    I believe it should be Alt+Enter

    How to identify from which word should be moved down?


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: VBA to insert line break (Alt+Enter)

    can you post a sample book.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  4. #4
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to insert line break (Alt+Enter)

    Haha - sorry, that'll teach me to talk and type. Yeah Alt+Enter.

    The cells are set to 40 width and word wrap is on, so really where each line ends as it is is where I need the break to be.

    I guess another way is Break at the first space that occurs prior to 40 characters (to ensure words aren't split)?

    Does that help?!?

  5. #5
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to insert line break (Alt+Enter)

    Sample Sheet
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: VBA to insert line break (Alt+Enter)


    Hi,

    the column width is not equal to the number of characters by line, check it !

  7. #7
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to insert line break (Alt+Enter)

    Hi..

    Don't worry about that. The main thing is whether there is a way to force the break at the end of each line.

    Anyone? ☺

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Re: VBA to insert line break (Alt+Enter)


    See InStrRev function to find out the break position …

  9. #9
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to insert line break (Alt+Enter)

    I've looked at that as you suggest, but I'm struggling to see how that could lead to the forced line break.

    Sorry if I'm being obtuse, but would appreciate any further insight if you're able to provide any?

  10. #10
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: VBA to insert line break (Alt+Enter)

    Hi..

    Rick Rothstein has made some nice code that will do what you want..

    The code. as it is.. outputs the result in the adjacent column.. change that as needed..

    http://www.excelfox.com/forum/f22/wr...-per-line-355/

    This question looks like it is directly related to the other thread you started.. how did you go with the solution i posted there for it?
    Last edited by apo; 05-10-2014 at 06:47 PM.

  11. #11
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to insert line break (Alt+Enter)

    Hi Apo,

    Thanks for your input on this and the other thread. You are right in that they are both connected to the same task.

    I will have a look at this later - I can only access at work, so replied are sporadic!

    Will update once I've had a read.


  12. #12
    Registered User
    Join Date
    09-08-2011
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    70

    Re: VBA to insert line break (Alt+Enter)

    Hi again Apo,

    Once again a perfect solution. I'd searched for a long time looking for a solution to this one and was beginning to think it was impossible.

    Very grateful indeed for all you help in both of these threads.

    Thanks again.

+ 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. ALT+ENTER = line break
    By Nyla in forum Excel General
    Replies: 5
    Last Post: 05-23-2006, 05:45 PM
  2. [SOLVED] Why can't I get 'alt enter' to create a line break in Excel?
    By babbott in forum Excel General
    Replies: 3
    Last Post: 05-08-2006, 07:25 PM
  3. Insert manual line break in formula
    By 0-0 Wai Wai ^-^ in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-11-2005, 03:15 PM
  4. [SOLVED] How do I enter a line break within a cell?
    By Striving for efficiency in forum Excel General
    Replies: 4
    Last Post: 11-17-2005, 04:15 PM
  5. [SOLVED] Insert maunal line break in formula
    By 0-0 Wai Wai ^-^ in forum Excel General
    Replies: 2
    Last Post: 09-10-2005, 12:05 PM

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