Splitting multiple row cells into new rows

cspearsall

New Member
Joined
May 23, 2016
Messages
19
Imaging - ready to work.xlsx
ABCDE
1Procedure NameModality TypeProcedure CodeCPT
2BI BREAST CYST ASPIRATION LEFTBreast ImagingIMG61719000 19000 3611900001PR PUNCTURE ASPIRATION CYST BREAST PR PUNCTURE ASPIRATION CYST BREAST HC PUNC/ASPIR BREAST CYST
3BI BREAST CYST ASPIRATION RIGHTBreast ImagingIMG195219000 19000 3611900001PR PUNCTURE ASPIRATION CYST BREAST PR PUNCTURE ASPIRATION CYST BREAST HC PUNC/ASPIR BREAST CYST
4BI BREAST DUCTOGRAM LEFTBreast ImagingIMG57977053 77053 4017705301CHG MAMMARY DUCTOGRAM OR GALACTOGRAM SINGLE CHG MAMMARY DUCTOGRAM OR GALACTOGRAM SINGLE HC MAMMARY DUCTOGRAM, SINGLE - MAMMO BREAST DUCTOGRAM
Epic - fill in (2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:G1,K1,I1Cell ValueduplicatestextYES



I need to find a way to make each of these matching rows in columns D & E into a separate row with the same information from columns A,B&C
 

Attachments

  • Excel Example.png
    Excel Example.png
    84.3 KB · Views: 2
Hi again,

For your actual database with over 1'300 records ... took the time to re-write the macro with Arrays ...
As requested ... it will significantly speed up your whole process
VBA Code:
Sub ArrayCopySplitRows()
' cspearsall  - Sat 8 Apr. 2023
' https://www.mrexcel.com/board/threads/splitting-multiple-row-cells-into-new-rows
Dim arr() As Variant
Dim Rng As Range
Dim last As Long
Dim i As Long, j As Long, k As Long
Dim cpt, pro

    ' Add Headers
    Sheet1.Range("A1:E1").Copy Sheet2.Range("A1:E1")
    last = Sheet1.Cells(Rows.count, 1).End(xlUp).row
    'Set range to populate array
    Set Rng = Sheet1.Range("A2:E" & last)
   
    'Resize array to match Final Range Size
    ReDim arr((Rng.Rows.count) * 3, Rng.Columns.count - 1)
   
    'Loop through each row and populate it 3 times to the Array '''
    ' Nb of Times - followed by Columns - followed by Rows
    For k = 0 To 2
        For j = 0 To Rng.Columns.count - 1
            For i = 0 To Rng.Rows.count - 1
                ' Watch the two Dimensions - k +( i * 3)
                arr(k + (i * 3), j) = Sheet1.Cells(i + 2, j + 1)
            Next i
        Next j
    Next k
    Sheet2.Range("A2:E" & (2 + ((Rng.Rows.count) * 3) - 1)).Value = arr
    ' Split Columns D & E - Using separator chr(10) '''
    For i = 2 To Sheet2.Cells(Rows.count, 4).End(xlUp).row Step 3
        cpt = Split(Sheet2.Range("D" & i), Chr(10))
        For j = LBound(cpt) To UBound(cpt)
            Sheet2.Cells(i + j, 4) = cpt(j)
        Next j
        pro = Split(Sheet2.Range("E" & i), Chr(10))
        For j = LBound(pro) To UBound(pro)
            Sheet2.Cells(i + j, 5) = pro(j)
        Next j
    Next i
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Hope this will help :)
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Is this what you are expecting for results.

Procedure NameModality TypeProcedure CodeCPTColumn1
BI BREAST CYST ASPIRATION LEFTBreast ImagingIMG61719000PR PUNCTURE ASPIRATION CYST BREAST
BI BREAST CYST ASPIRATION LEFTBreast ImagingIMG61719000HC PUNC/ASPIR BREAST CYST
BI BREAST CYST ASPIRATION LEFTBreast ImagingIMG6173611900001PR PUNCTURE ASPIRATION CYST BREAST
BI BREAST CYST ASPIRATION LEFTBreast ImagingIMG6173611900001HC PUNC/ASPIR BREAST CYST
BI BREAST CYST ASPIRATION RIGHTBreast ImagingIMG195219000PR PUNCTURE ASPIRATION CYST BREAST
BI BREAST CYST ASPIRATION RIGHTBreast ImagingIMG195219000HC PUNC/ASPIR BREAST CYST
BI BREAST CYST ASPIRATION RIGHTBreast ImagingIMG19523611900001PR PUNCTURE ASPIRATION CYST BREAST
BI BREAST CYST ASPIRATION RIGHTBreast ImagingIMG19523611900001HC PUNC/ASPIR BREAST CYST
BI BREAST DUCTOGRAM LEFTBreast ImagingIMG57977053CHG MAMMARY DUCTOGRAM OR GALACTOGRAM SINGLE
BI BREAST DUCTOGRAM LEFTBreast ImagingIMG57977053HC MAMMARY DUCTOGRAM, SINGLE - MAMMO BREAST DUCTOGRAM
BI BREAST DUCTOGRAM LEFTBreast ImagingIMG5794017705301CHG MAMMARY DUCTOGRAM OR GALACTOGRAM SINGLE
BI BREAST DUCTOGRAM LEFTBreast ImagingIMG5794017705301HC MAMMARY DUCTOGRAM, SINGLE - MAMMO BREAST DUCTOGRAM
Yes
 
Upvote 0
Here is the Power Query Solution associated with my previous post

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

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,094
Latest member
mystic19

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