Here's the problem:
I have a large spreadsheet filled with data across columns A:J. Each cell in each column contains a single value, EXCEPT columns F:H, which contain delimited data. I need to split these cells into multiple rows so that each row in the spreadsheet is unique and each cell has a single value.
I found the following thread, which got me most of the way: http://www.mrexcel.com/forum/excel-...ting-single-rows-data-into-multiple-rows.html
Specifically, this bit of code:
The problem with this code is that it splits columns one at a time. In my specific case, the columns containing delimited data have it in a specific order. For example, the first item in column F should pair with the first item in column G, which should pair with the first item in column H. Below is example data.
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Date[/TD]
[TD]Type[/TD]
[TD]Status[/TD]
[TD]Names[/TD]
[TD]Division[/TD]
[TD]Dept[/TD]
[TD]Lead[/TD]
[TD]Dept[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Oz,Kemp,Brown[/TD]
[TD]Med,Med,Eng[/TD]
[TD]Int Med,Hem Onc,Materials[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]James,Li,Shi,Ge[/TD]
[TD]Med,Med,LSA,Other[/TD]
[TD]Int Med,Int Med,Physics,[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]125[/TD]
[TD]Nanoemulsion[/TD]
[TD]8/5/2008[/TD]
[TD]Therapeutic[/TD]
[TD]Exclusive[/TD]
[TD]Wang,Sun[/TD]
[TD]Med,Med[/TD]
[TD]Allergy,Allergy[/TD]
[TD]Wang[/TD]
[TD]Allergy[/TD]
[/TR]
</tbody>[/TABLE]
I need the data in the following format:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Date[/TD]
[TD]Type[/TD]
[TD]Status[/TD]
[TD]Names[/TD]
[TD]Division[/TD]
[TD]Dept[/TD]
[TD]Lead[/TD]
[TD]Dept[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Oz[/TD]
[TD]Med[/TD]
[TD]Int Med[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Kemp[/TD]
[TD]Med[/TD]
[TD]Hem Onc[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Brown[/TD]
[TD]Eng[/TD]
[TD]Materials[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]James[/TD]
[TD]Med[/TD]
[TD]Int Med[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]Li[/TD]
[TD]Med[/TD]
[TD]Int Med[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]Shi[/TD]
[TD]LSA[/TD]
[TD]Physics[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]Ge[/TD]
[TD]Other[/TD]
[TD][/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]125[/TD]
[TD]Nanoemulsion[/TD]
[TD]8/5/2008[/TD]
[TD]Therapeutic[/TD]
[TD]Exclusive[/TD]
[TD]Wang[/TD]
[TD]Med[/TD]
[TD]Allergy[/TD]
[TD]Wang[/TD]
[TD]Allergy[/TD]
[/TR]
[TR]
[TD]125[/TD]
[TD]Nanoemulsion[/TD]
[TD]8/5/2008[/TD]
[TD]Therapeutic[/TD]
[TD]Exclusive[/TD]
[TD]Sun[/TD]
[TD]Med[/TD]
[TD]Allergy[/TD]
[TD]Wang[/TD]
[TD]Allergy[/TD]
[/TR]
</tbody>[/TABLE]
I have a large spreadsheet filled with data across columns A:J. Each cell in each column contains a single value, EXCEPT columns F:H, which contain delimited data. I need to split these cells into multiple rows so that each row in the spreadsheet is unique and each cell has a single value.
I found the following thread, which got me most of the way: http://www.mrexcel.com/forum/excel-...ting-single-rows-data-into-multiple-rows.html
Specifically, this bit of code:
Code:
Sub RedistributeData() Dim X As Long, LastRow As Long, A As Range, Table As Range, Cell As Range, Data() As String
Const Delimiter As String = ","
Const DelimitedColumn As String = "F"
Const TableColumns As String = "A:J"
Const StartRow As Long = 2
Application.ScreenUpdating = False
LastRow = Columns(TableColumns).Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
For X = LastRow To StartRow Step -1
Data = Split(Cells(X, DelimitedColumn), Delimiter)
If UBound(Data) Then
Intersect(Rows(X + 1), Columns(TableColumns)).Resize(UBound(Data)).Insert xlShiftDown
End If
Cells(X, DelimitedColumn).Resize(UBound(Data) + 1) = WorksheetFunction.Transpose(Data)
Next
LastRow = Cells(Rows.Count, DelimitedColumn).End(xlUp).Row
On Error GoTo NoBlanks
Set Table = Intersect(Columns(TableColumns), Rows(StartRow).Resize(LastRow - StartRow + 1))
On Error GoTo 0
For Each A In Table.SpecialCells(xlBlanks).Areas
A.FormulaR1C1 = "=R[-1]C"
A.Value = A.Value
Next
NoBlanks:
Application.ScreenUpdating = True
End Sub
The problem with this code is that it splits columns one at a time. In my specific case, the columns containing delimited data have it in a specific order. For example, the first item in column F should pair with the first item in column G, which should pair with the first item in column H. Below is example data.
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Date[/TD]
[TD]Type[/TD]
[TD]Status[/TD]
[TD]Names[/TD]
[TD]Division[/TD]
[TD]Dept[/TD]
[TD]Lead[/TD]
[TD]Dept[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Oz,Kemp,Brown[/TD]
[TD]Med,Med,Eng[/TD]
[TD]Int Med,Hem Onc,Materials[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]James,Li,Shi,Ge[/TD]
[TD]Med,Med,LSA,Other[/TD]
[TD]Int Med,Int Med,Physics,[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]125[/TD]
[TD]Nanoemulsion[/TD]
[TD]8/5/2008[/TD]
[TD]Therapeutic[/TD]
[TD]Exclusive[/TD]
[TD]Wang,Sun[/TD]
[TD]Med,Med[/TD]
[TD]Allergy,Allergy[/TD]
[TD]Wang[/TD]
[TD]Allergy[/TD]
[/TR]
</tbody>[/TABLE]
I need the data in the following format:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Title[/TD]
[TD]Date[/TD]
[TD]Type[/TD]
[TD]Status[/TD]
[TD]Names[/TD]
[TD]Division[/TD]
[TD]Dept[/TD]
[TD]Lead[/TD]
[TD]Dept[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Oz[/TD]
[TD]Med[/TD]
[TD]Int Med[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Kemp[/TD]
[TD]Med[/TD]
[TD]Hem Onc[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]123[/TD]
[TD]XXX Vaccine[/TD]
[TD]7/18/2008[/TD]
[TD]Other[/TD]
[TD]Active[/TD]
[TD]Brown[/TD]
[TD]Eng[/TD]
[TD]Materials[/TD]
[TD]Kemp[/TD]
[TD]Hem Onc[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]James[/TD]
[TD]Med[/TD]
[TD]Int Med[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]Li[/TD]
[TD]Med[/TD]
[TD]Int Med[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]Shi[/TD]
[TD]LSA[/TD]
[TD]Physics[/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]124[/TD]
[TD]DDX5[/TD]
[TD]7/21/2008[/TD]
[TD]Process[/TD]
[TD]Closed[/TD]
[TD]Ge[/TD]
[TD]Other[/TD]
[TD][/TD]
[TD]James[/TD]
[TD]Int Med[/TD]
[/TR]
[TR]
[TD]125[/TD]
[TD]Nanoemulsion[/TD]
[TD]8/5/2008[/TD]
[TD]Therapeutic[/TD]
[TD]Exclusive[/TD]
[TD]Wang[/TD]
[TD]Med[/TD]
[TD]Allergy[/TD]
[TD]Wang[/TD]
[TD]Allergy[/TD]
[/TR]
[TR]
[TD]125[/TD]
[TD]Nanoemulsion[/TD]
[TD]8/5/2008[/TD]
[TD]Therapeutic[/TD]
[TD]Exclusive[/TD]
[TD]Sun[/TD]
[TD]Med[/TD]
[TD]Allergy[/TD]
[TD]Wang[/TD]
[TD]Allergy[/TD]
[/TR]
</tbody>[/TABLE]