Forum Discussion
Move repeating columns into rows
- Dec 29, 2025
The prior answers show how to restructure the data using Power Query but to your question of keeping the comments that are in the cells when reformatting the structure I'm pretty sure you would have to use a custom macro for that. I created one here and will try to attach a sample file next:
Sub reformat_table() Application.ScreenUpdating = False Dim in_table, out_cell As Range Dim repeating_starting_column, repeating_count As Integer Dim ws As Worksheet Set ws = ActiveSheet Set in_table = ws.Range(InputBox("Select table range with repeating columns", "Input Table Range", Selection.Address)) Set out_cell = ws.Range(InputBox("Select cell for where output should be placed", "Output Table Location")) repeating_starting_column = 0 + InputBox("Column number where repeat begins", "Repeat Start") repeating_count = 0 + InputBox("Number of Columns that repeat", "Repeat Count") in_table.Range(in_table.Cells(0, 0), in_table(0, repeating_starting_column + repeating_count - 2)).Copy (out_cell.Cells(1, 1)) k = 2 For i = 1 To in_table.Rows().Count - 1 For j = repeating_starting_column - 1 To in_table.Columns().Count - 1 Step repeating_count If (in_table.Cells(i + 1, j + 1).Value2 <> "") Then in_table.Range(in_table.Cells(i, 0), in_table(i, repeating_starting_column - 2)).Copy (out_cell.Cells(k, 1)) in_table.Range(in_table.Cells(i, j), in_table(i, j + repeating_count - 1)).Copy (out_cell.Cells(k, 0 + repeating_starting_column)) k = k + 1 End If Next j Next i Application.ScreenUpdating = True End SubIf you highlight the source table before running the macro it will default that address range, then it will ask for the destination (cell), then the column where the first of the repeated columns starts (e.g. 2 in this example), and finally the number of columns that get repeated (e.g. again 2 in this example).
I am working as a blogger and managing my website, https://geeksevolution.com/. I spend nearly 12 hours a day on my work, so I want to automate as many tasks as possible using Microsoft Office tools. My goal is to save time, improve efficiency, and keep up with the fast pace of modern technology.