VBA to Split and fill

NeoSez

Board Regular
Joined
Aug 14, 2020
Messages
243
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am trying to figure out how to separate column D into separate cells in the same column just below the current row.
So, 001 Street will have a new row just below this one.
002 Street will have a new row just below this one.
003 Street will have a new row just below this one.
etcera
It should copy the preceding information with it.

tiles12x2410001 street
002 street
003 street
008 street
112 street
222 street
234 street
456 street
666 street
777 street
ladders30'2898 street
929 street
doors35x883555 street
666 street
777 street

The new chart will look something like this:
I hope this all makes sense.
tiles12x2410001 street
tiles12x2410002 street
tiles12x2410003 street
 
You're welcome. Glad we could help.
One more question:
Can I insert a blank row after each row has been converted to it's new rows?
So using this example, after all the tiles have been completed, insert blank row, then it will continue with the next row which is the Ladders etc.
tiles12x2410001 street
tiles12x2410002 street
tiles12x2410003 street
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
If you means after each row has been split then replace the redim with the line in green and add the line in blue:
Rich (BB code):
    ReDim arrOut(1 To maxLines + UBound(arrSrc), 1 To UBound(arrSrc, 2))    ' Added UBound(arrSrc) to allow for blank rows
  
    For i = 1 To UBound(arrSrc)
        splitCell = Split(arrSrc(i, splitColNo), vbLf)
        For j = LBound(splitCell) To UBound(splitCell)
            rowOut = rowOut + 1
            For iCol = 1 To UBound(arrSrc, 2)
                arrOut(rowOut, iCol) = arrSrc(i, iCol)          ' should skip column 19 but it will get overwritten anyway
            Next iCol
            arrOut(rowOut, splitColNo) = splitCell(j)
        Next j
        rowOut = rowOut + 1                                     ' Insert Blank Row
    Next i
 
Upvote 1
If you means after each row has been split then replace the redim with the line in green and add the line in blue:
Rich (BB code):
    ReDim arrOut(1 To maxLines + UBound(arrSrc), 1 To UBound(arrSrc, 2))    ' Added UBound(arrSrc) to allow for blank rows
 
    For i = 1 To UBound(arrSrc)
        splitCell = Split(arrSrc(i, splitColNo), vbLf)
        For j = LBound(splitCell) To UBound(splitCell)
            rowOut = rowOut + 1
            For iCol = 1 To UBound(arrSrc, 2)
                arrOut(rowOut, iCol) = arrSrc(i, iCol)          ' should skip column 19 but it will get overwritten anyway
            Next iCol
            arrOut(rowOut, splitColNo) = splitCell(j)
        Next j
        rowOut = rowOut + 1                                     ' Insert Blank Row
    Next i
Perfection! A thousand thanks Alex.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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