Forum Discussion
diegohoutart
Nov 27, 2019Copper Contributor
Convert list of data to table
Hello everyone, I have a data set of this form: Author Author1 Title Title1 Date Date1 Author Author2 Title Title2 Date Date2 Author Author3 Title Title3 Date ...
Smitty Smith
Nov 27, 2019Former Employee
diegohoutart This should do what you want. It will build a new list in the format you want, starting in cell D1, so make sure D:F are empty.
Sub SplitAuthors()
Dim i As Long
Dim lr1 As Long
Dim lr2 As Long
lr1 = Cells(Rows.Count, "B").End(xlUp).Row
Range("D1").Value = "Author"
Range("E1").Value = "Title"
Range("F1").Value = "Date"
For i = 1 To lr1 Step 3
lr2 = Cells(Rows.Count, "D").End(xlUp).Offset(1).Row
Cells(lr2, "D").Value = Cells(i, "B").Value
Cells(lr2, "E").Value = Cells(i + 1, "B").Value
Cells(lr2, "F").Value = Cells(i + 2, "B").Value
Next i
End Sub
diegohoutart
Nov 27, 2019Copper Contributor
Thanks for your help. I have to say that I am a mere beginner. How do I run this code ?
- Smitty SmithNov 28, 2019Former Employee
diegohoutart You can right-click any sheet tab, select View Code, which will open the Visual Basic Editor (VBE). Then go to Insert > Module, and paste the code in the new window that opens on the right. Alt+Q will exit you back to Excel. You can run the code by selecting it from the Macros pane (Alt+T+M+M), then press Run. You can also run it from the Developer tab > Macros.
Sergei - That's a great solution. I had thought about doing it with PQ, but didn't even think of using an Index & divisor.