Insert hard return (chr 10) in specific place

therobinnorman

New Member
Joined
Nov 12, 2016
Messages
8
Merry Christmas (eve) to all those viewing my thread.

Here's the deal. I have a worksheet with text in cell A1. How do I alter the cell to only allow 69 characters per line, and then auto-enter a chr10? Everything needs to remain in cell A1, if at all possibly. I need it to not cut off any words, nor enter a hypen. Adjusting the cell length works in excel, but when I copy/paste into my other program the line breaks disappear. VBA or excel functions are fine.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi

Not enough information. Can you clarify?

1 - How long will the text be, can it be more than 2 lines?
2 - Does the text already have some linefeeds (chr 10)?
3 - Do you want the text always to be cut at a space character? In that case do you want to replace the space character with a linefeed or to keep the space and add a linefeed?

... or did you have in mind some other set of rules to divide the text?
 
Upvote 0
You might try the following...

Code:
Sub test69()
Dim i As Long, j As Long
Dim r As Range
Set r = Range("A1")
j = Len(r)

For i = 69 To Len(r) Step 69
    If i Mod 69 = 0 And Mid(r, i, 1) = " " Then
        r.Value = Mid(r, 1, i) & Chr(10) & Mid(r, i + 1, j)
    Else
        Do Until Mid(r, i, 1) = " "
            i = i - 1
        Loop
        r.Value = Mid(r, 1, i) & Chr(10) & Mid(r, i + 1, j)
    End If
Next i
End Sub

Cheers,

tonyyy
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top