How to Convert Excel Columns to Rows Based on a Name or Group
Question details
The user needs to transform vertical column data into grouped horizontal records, where each specific duct name or category triggers a new row.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Reformatting thousands of rows of stacked vertical data into a structured horizontal layout for better readability and data analysis.
- Observed behavior
- Data is currently listed vertically in a single or few columns, and the standard Paste Transpose feature cannot dynamically group thousands of rows based on header names.
Before applying macros or complex offset formulas, verify whether your data groups have a fixed number of rows (e.g., exactly 7 rows per group) or variable sizes, as this determines the best method to use.
Use a VBA Macro to Group and Transpose Variable Data
This is the most robust method for converting columns to rows when your groups vary in size. It automatically detects your specific group header text to start new rows.
When dealing with variable group sizes, standard formulas often fall short. A VBA macro can loop through your source data, identify a designated group name (such as "ELECTRICAL DUCT"), and automatically pivot the related values across new columns in a fresh worksheet.
Open your workbook and press Alt + F11 on your keyboard to launch the Visual Basic for Applications Editor.
Click on 'Insert' in the top menu bar, then select 'Module' to open a new blank coding window.
Write or paste your macro script. The logic should loop through your data rows (e.g., For s = 2 To m) and use an IF statement like `If wsS.Cells(s, 1).Value Like "ELECTRICAL DUCT*" Then` to trigger a row increment (t = t + 1) and reset the column counter (c = 0).
Press F5 or click the 'Run' button in the toolbar. The macro will process the dataset and output the newly formatted horizontal records into an automatically created worksheet.

Apply the OFFSET Formula for Fixed-Size Groups
If every data group contains exactly the same number of rows, you can use the OFFSET formula to extract and transpose the data without writing any code.
Easily Transpose and Group Data with WPS Spreadsheet
WPS Spreadsheet offers powerful built-in developer tools and advanced formula support, making it incredibly easy to manage, group, and transpose massive datasets with precision.
- 1. Open Your Data: Launch WPS Spreadsheet and open your dataset containing the vertical columns.
- 2. Access Developer Tools: Navigate to the 'Developer' tab on the top ribbon. If you are using formulas, simply select your target cell and use the formula bar.
- 3. Run Macros or Formulas: Click 'VB Editor' to input your transposition script or enter your OFFSET formulas directly to group the data.
- 4. Save the Document: Once your data is transposed horizontally, save your workbook in your preferred format such as .xlsx.

Frequently Asked Questions
Can I convert columns to rows by group without using VBA?
Yes, if your data groups have a strictly fixed number of rows, you can use formulas like OFFSET, INDEX, or INDIRECT to mathematically extract the data into rows. Alternatively, you can use Power Query to pivot and group the data without any coding.
Why does my OFFSET formula return zeros or #REF! errors?
This typically occurs if the sheet name in the formula doesn't match your actual source sheet, or if the row/column offset calculation points to empty or non-existent cells. Double-check your absolute references (the $ symbol) and ensure your group multiplier exactly matches the number of rows per group.
Does the standard Paste Special > Transpose option work for this?
No, the standard Paste Transpose feature only flips a single, contiguous block of data. It cannot evaluate group header names or automatically wrap a single column of thousands of rows into multiple horizontal records.
How do I enable macros to run the transposition code?
Before executing a VBA script, ensure macros are enabled in your software. Go to the Developer tab and check your Macro Security settings, ensuring that you permit the execution of VBA scripts for your trusted workbook.




