Splitting text with line breaks with repeating adjacent data

Scott F

New Member
Joined
Jun 2, 2022
Messages
2
Office Version
  1. 365
Platform
  1. MacOS
Is it possible to split line broken text from one column and repeat the data from adjacent columns as shown? The values in the data column are in a single cell per row with line breaks.
Screenshot.png
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Column3", Splitter.SplitTextByDelimiter("#(lf)", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Column3")
in
    #"Split Column by Delimiter"

Book2
ABCDEFG
1Column1Column2Column3Column1Column2Column3
2Company1Phone1Data1 Data2 Data3 Data4Company1Phone1Data1
3Company2Phone2Data1 Data2 Data3 Data4Company1Phone1Data2
4Company1Phone1Data3
5Company1Phone1Data4
6Company2Phone2Data1
7Company2Phone2Data2
8Company2Phone2Data3
9Company2Phone2Data4
Sheet1
 
Upvote 0
Try this:
VBA Code:
Sub Scott_1()
Dim i As Long, k As Long
Dim va, vb, ary, x
va = Range("A2", Cells(Rows.Count, "A").End(xlUp)).Resize(, 3)

ReDim vb(1 To UBound(va, 1) * 5, 1 To 3)  'I'm assuming the average number of phone in each company is no more than 5

For i = 1 To UBound(va, 1)
    ary = Split(va(i, 3), vbLf)
        For Each x In ary
            k = k + 1
            vb(k, 1) = va(i, 1)
            vb(k, 2) = va(i, 2)
            vb(k, 3) = x
        Next
Next

'put the result in sheet2
Sheets("Sheet2").Range("A2").Resize(k, 3) = vb
End Sub

Notes:
  1. I'm assuming the average number of phone in each company is no more than 5.
  2. I put the result in sheet2.
Example:
Book1
ABC
1
2Company 1phone 11234 1235 1236
3Company 2phone 21237
4Company 3phone 31238 1239
Sheet5

Result:
Book1
ABC
1
2Company 1phone 11234
3Company 1phone 11235
4Company 1phone 11236
5Company 2phone 21237
6Company 3phone 31238
7Company 3phone 31239
Sheet2
 
Upvote 0
Perhaps this as a formula option:
Lambda-map examples.xlsx
MNO
4Company 1Phone 1Data 1 Data 2 Data 3 Data 4
5Company 2Phone 2Data 1 Data 2 Data 3 Data 4
6
7
8Company 1Phone 1Data 1
9Company 1Phone 1Data 2
10Company 1Phone 1Data 3
11Company 1Phone 1Data 4
12Company 2Phone 2Data 1
13Company 2Phone 2Data 2
14Company 2Phone 2Data 3
15Company 2Phone 2Data 4
Sheet3
Cell Formulas
RangeFormula
M8:O15M8=LET(a,M4:M5,b,N4:N5,c,O4:O5, x,WRAPROWS(DROP(TEXTSPLIT(TEXTJOIN("",TRUE,REPT(a&", "&b&", ",LEN(c)-LEN(SUBSTITUTE(c,CHAR(10),""))+1)),", "),,-1),2), HSTACK(x,TEXTSPLIT(TEXTJOIN(CHAR(10),TRUE,c),,CHAR(10))))
Dynamic array formulas.
 
Upvote 0

Forum statistics

Threads
1,216,525
Messages
6,131,183
Members
449,630
Latest member
parkjun

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