Formatting Issues

Create Parent-Child Levels from Indented Text in Excel

Ayan MasoodAyan Masood Nov 18, 2026 869 views

Question details

The user wants to represent parent-child levels in an Excel list where hierarchy is shown by indentation.

Create Parent-Child Levels from Indented Text in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet contains a list of items whose parent-child relationships are indicated visually by indentation.
Observed behavior
The user needs a way to record hierarchy levels, display indentation, and optionally collapse related child rows.
Before you start

Check whether the indentation consists of leading spaces or Excel cell formatting. Have a hierarchy level available for each row, or plan to enter one manually; visual indentation alone does not provide a level value for the formula below.

Solution 1Recommended

Use a helper column to display hierarchy levels

Use this method when you can assign a numeric level to each row and want to display consistent indentation.

The formula displays indentation from the supplied level; it does not determine parent-child relationships automatically. Use level 0 for top-level items, 1 for their children, and higher numbers for deeper levels.

1
Prepare the item and level columns

Place the item text in column A and enter a nonnegative whole-number level for each corresponding row in column B. If the original text contains leading spaces, remove them before applying the formula.

2
Enter the indentation formula

In cell C1, enter =REPT(" ",3*B1)&A1. The formula adds three spaces for each level before the text in A1.

3
Fill the formula down

Select C1 and drag the fill handle down alongside the remaining rows. Adjust the level values in column B if an item appears at the wrong depth.

Use a helper column to display hierarchy levels
Display versus relationships: The indented text is a visual representation. Keep the level column if you need to identify the depth of each item later.
Work with hierarchies in WPS

Display Parent-Child Levels in WPS Spreadsheet

Use a level helper column and the REPT formula in WPS Spreadsheet to display a consistent hierarchy in your list.

  1. 1. Open the workbook: Open WPS Spreadsheet and use Open to select your Excel workbook.
  2. 2. Enter hierarchy levels: Place item text in column A and enter its level in column B, using 0 for a top-level item and 1 or more for children.
  3. 3. Add the formula: Select C1 and enter =REPT(" ",3*B1)&A1 to display the item with three spaces per level.
  4. 4. Fill and save: Drag the fill handle from C1 down the list, then choose File > Save As and select an Excel workbook format such as XLSX.
Display three spaces per hierarchy level with a formulaEdit level values to adjust indentationOpen and save Microsoft Excel XLSX filesUse a familiar spreadsheet interface for everyday editing
microsoft office alternative - wps office

Frequently Asked Questions

Can the REPT formula detect Excel's visual indent setting?

No. The formula uses the numeric level supplied in the helper column. If indentation is cell formatting rather than leading spaces, enter or otherwise obtain the levels before using the formula.

How do I change the number of spaces per level?

Change the multiplier in =REPT(" ",3*B1)&A1. For example, use 2*B1 for two spaces per level, then fill the updated formula down column C.

How do I keep a parent row visible when collapsing its children?

Select only the consecutive child rows beneath the parent, then choose Data > Group in Excel. Use the minus control beside the rows to collapse the group.

Does indenting text automatically create a collapsible hierarchy?

No. The REPT formula changes the displayed text only. To add expand and collapse controls in Excel, select related child rows and use Data > Group.