+ Reply to Thread
Results 1 to 4 of 4

Automatic Line Break at X number of characters

Hybrid View

  1. #1
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,306

    Re: Automatic Line Break at X number of characters

    Hey duyane,

    If you decrease the EndPtr instead of increase it you could keep the line length under 50 and still word break.
    Sub LineBreak2()
    Dim StartPtr As Double
    Dim EndPtr As Double
    Rows(18).EntireRow.ClearContents
    StartPtr = 1
    EndPtr = 50
    
    Do Until EndPtr > Len(Cells(1, "A"))
        Do Until Mid(Cells(1, "A"), EndPtr, 1) = " "
        ' Debug.Print Mid(Cells(1, "A"), EndPtr, 1);
            EndPtr = EndPtr - 1
        Loop
    
        Cells(18, "A") = Cells(18, "A") & Mid(Cells(1, "A"), StartPtr, EndPtr - StartPtr) & vbCrLf
        StartPtr = EndPtr + 1
        EndPtr = StartPtr + 50
    
    Loop
    
    End Sub
    Last edited by MarvinP; 07-17-2012 at 02:15 AM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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