Say you’re working on a project report in Google Sheets and want to list tasks with their sub-tasks. To make the sub-tasks stand out, you can add an indent.
This way, the main tasks are on the left, and the sub-tasks are slightly to the right, making your list easy to read and understand at a glance.
For example, you have a primary task called “Marketing Plan” and sub-tasks like “Social Media Strategy” and “Email Campaigns”.
You can add an indent before the text to indent the sub-tasks. It creates a visual hierarchy, showing that these sub-tasks belong to the main task.
Unlike Excel, Google Sheets has no direct option to add Indent. There used to be an option in the format menu, but now this option is not there anymore.
But there are other ways to add an indent in a cell that you can use. So, let’s get started…
Quick Notes
Here are the quick ways to add indentation to a cell or a range.
- In the custom formatting option, you can enter ” “@ to apply a single space indentation to the cell.
- You can also write Google App Script to create a custom option to add Indent to the Google Sheets menu.
- You can manually enter a space in the cell before the text to enter an indent.
- You can also use the REPT function to combine a space with the value in the cell.
Now, let’s learn each of these methods in detail.
Apply Indent using the Custom Formatting Option
It is one of the best ways to add the Indent. The reason is that using this method will not change the value when you have a number in a cell instead of a text. And you can use that number further.
- First, select the cell or the range of cells where you want to add an indent.
- Now, go to Format in the top menu. Hover over the number and click “Custom Number Format” at the bottom.
- After that, in the Custom Format field, enter a format like ” “@. The spaces inside the quotes determine the size of the Indent. One space means one Indent, and you can add more spaces for a larger indent.
- Finally, click “Apply” to set the custom number format with indentation.
If you want to add more than one space indentation, you need to add more than one space within the double quotation marks.
The best part of this method is that when you apply the custom format, it stays in the format list, and you can add other cells or a range just by going to the Toolbar > More Formats.
Create a New Option with Google App Script for Indent
Yes, we can create a custom menu option for Indent, which you can use like normal options in Google Sheets.
In the below example, I have a custom option that says “Add Indent,” and when you use this option, it adds an indent to the selected cells.
And here is the code that you can use:
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Custom Option')
.addItem('Add Indent (by ExcelChamps.com) ', 'addCustomIndentation')
.addToUi();
}
function addCustomIndentation() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getActiveRange();
var numSpaces = 2; // Change this Number to set the desired number of spaces for the indent
var indentSpaces = ' '.repeat(numSpaces);
var customFormat = '"' + indentSpaces + '"@';
range.setNumberFormat(customFormat);
}
To use this code, open the Google Apps Script editor (Extensions > Apps Script), paste the code there, and click the “Save” button. Then, reload your Google Sheets workbook.
When you select “Add Indent” from the menu, the script applies a custom number format to the selected cells, adding a specified number of spaces before the text to create an indent.
If you only want to have code that can apply Indent to the selected cells, you can use the below code:
function addCustomIndentation() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getActiveRange();
var numSpaces = 2; // Change this Number to set the desired number of spaces for the Indent
var indentSpaces = ' '.repeat(numSpaces);
var customFormat = '"' + indentSpaces + '"@';
range.setNumberFormat(customFormat);
}
Use a Space Before the Value as an Indent
To create an indent, add a space before the value in each cell.
- Click on the cell where you want to add the Indent. Then, double-click on the cell with the mouse or press F2 to enter edit mode.
- After that, press the spacebar a few times to add spaces before your text. The number of spaces you add will determine the size of the Indent. After adding the desired number of spaces, type your text as usual.
- Press Enter to apply.
Like our example, you can add three or five spaces before each sub-task to make them appear indented.
Using REPT to Add Indent before a Value
REPT repeats any character the specified number of times. To add indentation, you can combine space with the actual value from the cell to have an Indent in the final value.
Type the formula =REPT(” “, number_of_spaces) & “Text”. Replace number_of_spaces with the number of spaces you want for the Indent and “Text” with the actual text you want to indent.
In the above example, the formula =REPT(” “, 2) & A3 is used in cell B3. In this formula, REPT(” “, 2) repeats the space character (” “) two times. It creates an indent by adding two spaces before the text.
The & operator concatenates the repeated spaces with the text in cell A3. The & operator concatenates the repeated spaces with the text in cell A3. A3 refers to the cell containing the text “Social Media Strategy, ” a sub-task.
My Take
Indentation is helpful because it organizes information clearly and structured, making data more accessible to read and understand.
You asked me about the best method. The first two methods use custom formatting.
If you want to apply the Indent only once, then the first method is good, but if you want to add Indent frequently, you can create a custom option for this on the menu so that you can use it again and again without any problem.