Forum Discussion
Need Help with turning columns into rows
- Sep 08, 2022
Sub worker() Dim i As Long Dim j As Long Dim m As Long Dim k As Long Dim l As Long Dim n As Long Range(Cells(15, 1), Cells(1048576, 5)).Clear i = Range("A" & Rows.Count).End(xlUp).Row m = 15 For j = 2 To i Range(Cells(m, 1), Cells(m + 2, 1)).Value = Cells(j, 1).Value Range(Cells(m, 2), Cells(m, 5)).Value = Range(Cells(j, 2), Cells(j, 5)).Value Range(Cells(m + 1, 2), Cells(m + 1, 5)).Value = Range(Cells(j, 6), Cells(j, 9)).Value Range(Cells(m + 2, 2), Cells(m + 2, 5)).Value = Range(Cells(j, 10), Cells(j, 13)).Value m = m + 3 Next j l = Range("A" & Rows.Count).End(xlUp).Row For n = 15 To l If IsEmpty(Cells(n, 2)) And Not (IsEmpty(Cells(n, 1))) Then Range(Cells(n, 1), Cells(n, 5)).Delete n = n - 1 Else End If Next n End SubMaybe with these lines of code. In the attached file you can click the button in cell F10 to run the macro. If the table with original data is large (e.g. 1000 rows) the result table can be in columns P to T for example.
Tami_E This is a complicated one... are you familiar with Power Query?
What I did was
1) use Get Data/From Table Range
2) duplicate the entire table twice
3) select the worker, and then Ctrl + Select the individual columns pertaining to that section of the original range (original, first change, second change) and then right click to "remove other columns"
4) Ensured that each column had the same name and data type as the first (e.g. changing the name from Effective Date First Change to Start Date to match the original)
5) Appended all three queries.
Hoping others can come up with an easier solution.