macro or formula to break text up to fit column width 86

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

So I have a list of information in excel that i need broken up but cant think how to do it?
so Col;umn C hold my current T&C as lots of rows of data.
some and just short sentances that fit nicely into my sheet but the problem is when i get long sentences / content in one cell.
i either set it to text wrap which makes th rows expand messing up the look of the page as there are other things in columns next to it or i turn off text wrap and one the text goes past the end of the cell i loss it
so i want to break my text up.
its a one off thing so i don't mind if it a formula and i have to play around with it or it a macro that just does it but this is what i want.

I have put the Text into a clean sheet that just holds the data down column A the column width is 86 and the text size is calibri 8.5
id like split up the cells so no text goes past the end of the cell put the extra text underneath the row it was taken from
some of these will be text rows will need multiple rows to get all the data in
i don't mind if its a copy put into a new sheet (I have one called "New") or just next to the current data in couln b or c or even edited as in place i just need the result.
please help if you can
Thanks
Tony
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
If you establish how many characters you want to display in each cell (say 86) then by adding a row above with multiples of this number you can split the text easily in to chunks of (say 86) characters.


Book1
ABCDEFGHIJ
1TEXT86172258344430516602688774
2Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tincidunt lobortis feugiat vivamus at. Massa vitae tortor condimentum lacinia quis vel eros donec ac. In ante metus dictum at. Ultricies tristique nulla aliquet enim tortor at. Libero nunc consequat interdum varius sit amet mattis vulputate. Enim praesent elementum facilisis leo vel fringilla. Ipsum suspendisse ultrices gravida dictum fusce ut. Facilisi nullam vehicula ipsum a arcu cursus vitae congue. Faucibus nisl tincidunt eget nullam non nisi est sit. Porta lorem mollis aliquam ut porttitor leo. Bibendum est ultricies integer quis auctor elit sed vulputate mi. Amet tellus cras adipiscing enim eu. In massa tempor nec feugiat nisl. Enim nunc faucibus a pellentesque sit amet. Nec nam aliquam sem et tortor consequat id. Dolor sit amet consectetur adipiscing elit pellentesque habitant. Luctus venenatis lectus magna fringilla urna. Fames ac turpis egestas maecenas pharetra. Nulla facilisi etiam dignissim diam quis enim lobortis scelerisque. Mi tempus imperdiet nulla malesuada. Nunc faucibus a pellentesque sit.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incidid
Sheet1
Cell Formulas
RangeFormula
C1:J1C1=B1+86
B2:J2B2=LEFT(A2,B1)
 
Upvote 0
thanks Stu,
this is good but it breaks the words in half is a word is say 84 to 90,
what i could do with is it breaking up the text but if the 86 is a word go back to space and cut from there,
any ideas how i could do this anyone?
Thanks
Tony
 
Upvote 0
Sorry, I've tried several different things with this but not getting anywhere - anybody else?
 
Upvote 0
Try this:
VBA Code:
Sub a1122681a()
'https://www.mrexcel.com/board/threads/macro-or-formula-to-break-text-up-to-fit-column-width-86.1122681/#post-5418645
Dim i As Long, j As Long, n As Long
Dim g As Long, xz As Long, x As Long
Dim va, vb

n = Range("A" & Rows.Count).End(xlUp).Row
va = Range("A2:A" & n)
ReDim vb(1 To n, 1 To 100)
xz = 86  'change to suit

For i = 1 To n - 1
    If Len(va(i, 1)) > xz Then
        g = 0
        Do
            x = InStrRev(va(i, 1), " ", xz, vbTextCompare)
            If x = 0 Then vb(i, g + 1) = va(i, 1): Exit Do
            g = g + 1
            vb(i, g) = Mid(va(i, 1), 1, x)
            va(i, 1) = Mid(va(i, 1), x + 1)
        
        Loop Until x = 0
    
    Else
    vb(i, 1) = va(i, 1)
    End If
    
Next

Range("B2").Resize(n, 100) = vb

End Sub

EXAMPLE:
Book1
ABCD
1
2Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tincidunt lobortis feugiat vivamus at. Massa vitae tortor condimentum lacinia quis vel eros donec ac.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Tincidunt lobortis feugiat vivamus at. Massa vitae tortor condimentum lacinia quis vel eros donec ac.
3magna aliqua. magna aliqua.
4asdasd
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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