Splitting multiple lines in a cell into multiple rows with reference cell

Galaxorian

New Member
Joined
Sep 30, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hey there,

I have a question (see title). I have this:
Example what I want.png


And want to accomplish this:
Example what I want 2.png



This is for like 11000 companies. Every cell in column B holds the amount of companies in an alliance (2 or more) but the cross equity transfger is specified only once. How do I make it that every row shows the company name AND the correct cross equity transfer.

Thanks in advance kind strangers!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
If you want to do this through macro then see the code below...

VBA Code:
Sub SplitNArrange()
    Dim CellValue As Variant, CounterRows As Integer, CounterLines As Integer
    
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    
    For CounterRows = Split(ActiveSheet.UsedRange.Address, "$")(4) To 1 Step -1
        CellValue = ActiveSheet.Range("B" & CounterRows).Value
        
        If CellValue Like "*" & vbLf & "*" Then
            CellValue = Split(CellValue, vbLf)
            
            For CounterLines = LBound(CellValue) To UBound(CellValue)
                ActiveSheet.Rows(CounterRows + CounterLines + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
                ActiveSheet.Range("A" & CounterRows + CounterLines + 1).Value = CellValue(CounterLines)
                ActiveSheet.Range("B" & CounterRows + CounterLines + 1).Value = ActiveSheet.Range("C" & CounterRows).Value
            Next CounterLines
            
            ActiveSheet.Rows(CounterRows).Delete
        End If
    Next CounterRows
    
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    Beep
    MsgBox "Completed"
End Sub

P.S. Do not use this on your original document without testing it first.
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,640
Members
448,974
Latest member
DumbFinanceBro

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