How to Nest Values from Two Excel Columns Under a Main Column
Question details
The user needs to group and nest values from two columns (B and C) under the corresponding main values in column A, outputting the result into a single-column hierarchy rather than a PivotTable. Duplicate combinations must be skipped.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Preparing a flat, single-column data hierarchy for upload to a portal that does not support PivotTable formatting.
- Observed behavior
- The user requires a transformed, multi-column dataset nested into a single column without relying on PivotTables, as standard PivotTables retain formatting that is incompatible with the target portal.
Ensure your original dataset is formatted as an Excel Table (Ctrl+T) to make it easier to load into Power Query or process with VBA without hardcoding specific cell ranges.
Use Power Query to Combine and Nest Columns
Power Query provides a robust, refreshable way to combine columns B and C and group them under column A without using complex VBA code.
Power Query is highly recommended for this task because it handles data transformation natively, avoids VBA errors like 'Subscript out of range', and can be easily refreshed when your source data changes.
Select any cell in your data table, navigate to the 'Data' tab on the ribbon, and click 'From Table/Range' to open the Power Query Editor.
Select Column B and Column C by holding the Ctrl key. Right-click the column headers and choose 'Merge Columns'. Specify a separator if necessary, name the new column, and click 'OK'.
Select Column A, navigate to the 'Home' tab, and click 'Group By'. Choose 'All Rows' as the operation to retain your newly merged column data within the grouping.
Expand the grouped table column to display the nested values. Select the merged column, click 'Remove Duplicates' on the 'Home' tab to ensure duplicate combinations are skipped.
Once your single-column hierarchy is formatted correctly, click 'Close & Load' on the Home tab to output the transformed, flat data to a new Excel worksheet.

Use VBA with Scripting.Dictionary to Create a Single-Column Hierarchy
A VBA macro can programmatically group values and build a single-column hierarchy using Dictionary and Collection objects for more complex custom requirements.
Looking for a Lightweight Spreadsheet Tool?
While complex Power Query transformations are native to Microsoft Excel, WPS Office provides a fully featured, lightweight alternative for standard data analysis. Enjoy high compatibility with Microsoft formats, powerful formulas, and a familiar interface—all completely free.

Frequently Asked Questions
Why do I get a 'Subscript out of range' error when using VBA for this?
This error typically occurs when your VBA array or dictionary attempts to access an index that doesn't exist, such as when Data(i, 2) references an uninitialized array element. Ensure your data ranges are defined correctly and that empty rows are accounted for in your code loop.
Why can't I just use a PivotTable for this hierarchy?
While PivotTables excel at grouping and nesting data visually, they use a specific background format. If you need to upload the resulting list to a web portal or third-party tool, PivotTable formatting is usually unsupported, requiring a raw, single-column flat list instead.
How do I remove duplicates in Power Query after combining columns?
In the Power Query Editor, right-click the header of your combined column and select 'Remove Duplicates'. This guarantees that any duplicate nested combinations are skipped in your final output before loading the data back into Excel.
Can I use dynamic array functions to achieve this instead?
Yes, in newer versions of Excel, dynamic array formulas like UNIQUE, FILTER, and VSTACK can theoretically be combined to build a single-column hierarchy without Power Query or VBA, though it requires highly complex formula nesting that can be difficult to maintain.




