Hello,
I currently have data that reads like the attached. I've gotten quite far cobbling some code together but for the life of me I just can't figure out this last moderation. Can somebody help adjust my code so that the semicolon separated values are split in columns B & C simultaneously and create corresponding rows below with the original rows data in the remaining columns (A, D, E, F, G) ?
The workbook attached contains three tabs. Raw is the raw datam Current Output is the result of my current macro which is also included in the workbook, and Desired Output is what I want it to look like after the macro. Any help would be greatly appreciated, thank you!
Code:
Sub cobble()
Dim rng As Range
Dim r As Long
Dim arrParts() As String
Dim partNum As Long
Dim X As Range
Sheets("Raw").Select
Cells.Select
Selection.Copy
Sheets("Current Output").Select
ActiveSheet.Paste
Range("A1").Select
Sheets("Current Output").Select
'step 2
Set rng = Range("A1:G13876")
r = 2
Do While r <= rng.Rows.Count
'Split the value in column B (2) by commas, store in array
arrParts = Split(rng(r, 2).Value, ";")
'If there's more than one item in the array, add new lines
If UBound(arrParts) >= 1 Then
rng(r, 2).Value = arrParts(0)
'Iterate over the items in the array
For partNum = 1 To UBound(arrParts)
'For partNum1 = 1 To UBound(arrParts1)
'Insert a new row '
'increment the row counter variable
r = r + 1
rng.Rows(r).Insert Shift:=xlDown
'Copy the row above '
rng.Rows(r).Value = rng.Rows(r - 1).Value
'update the part number in the new row '
rng(r, 2).Value = Trim(arrParts(partNum))
'resize our range variable as needed
Set rng = rng.Resize(rng.Rows.Count + 1, rng.Columns.Count)
Next
End If
cobble.xlsm
'increment the row counter variable
r = r + 1
Loop
End Sub
Bookmarks