In this tutorial, you will learn how to group rows in Google Sheets. Grouping rows in Google Sheets allows you to organize and summarize related data. Row groups can then be expanded and collapsed with a single click to show or hide the data in that group. This is useful when you want to keep detailed information in the spreadsheet for reference, but
want the option to view a more concise, summarized dataset.Grouped Rows Expanded
Grouped Rows Collapsed
Notice in the screenshots above how much space is saved with the row groups hidden.
You can also achieve a similar result by hiding the rows instead of grouping them, but hiding rows is less versatile as you have to select the exact rows you want to hide each time.
In contrast to hidden rows, grouped rows remain grouped even when the group is expanded, which makes it easy to show and hide these rows quickly without having to select specific rows each time.
Group Rows in Google Sheets
To group rows in Google Sheets, follow these steps:
- Select the rows you want to group. Note that the grouped rows must be adjacent
- Open the Data menu
- Scroll down to the Group Rows option and click on it. This option is at the bottom of the menu
- The rows you selected are now grouped
Expanding & Collapsing Row Groups
When you group rows in Google Sheets, you’ll see a small minus sign [-] appear to the left of the row numbers:
Click on minus to collapse the group. Then click on the plus sign that takes its place to expand again
You can also expand and collapse row groups using hotkeys. Do do this, select a range of rows that includes the group or groups you wish to expand or collapse and use the following keyboard shortcuts:
Windows
Expand: Alt + Shift + Down Arrow
Collapse: Alt + Shift + Up Arrow
Mac:
Expand: Option + Shift + Down Arrow
Collapse: Option + Shift + Up Arrow
Ungrouping Rows
It’s also easy to remove row groups you no longer need, but remember that you can always expand the group to view the grouped rows without removing the group.
Removing row groups is much the same as adding them:
- Select the rows in the group you want to remove. This can be done easily by collapsing and then expanding the group, which automatically selects all rows in the group
- Open the Data menu
- Scroll down to the Ungroup Rows option and click on it
- Your rows are now ungrouped
Summary
Example Spreadsheet: Make a copy of the example spreadsheet
In this tutorial, I covered how to group rows in Google Sheets. Want more? Check out all the Google Sheets Tutorials.
You might also like:
So I've got this Google Sheets file where I'm using one of the sheets as a log / history for registering some values.
My time trigger which will call the function which records data to the log is set by the user. Regardless if the user chooses 1 minute interval or maybe 5, 10, 15 minutes and so on, soon the log sheet will be overpopulated. So I'd like a way for the record script I've got on the Script Editor to automatically group rows as these are being added/recorded on the log sheet automatically by the time trigger, by day and also by month simultaneously. This means Month groups and within these day subgroups and within each of these the 1 minute, or 5 etc, rows were recorded. This would improve navigation of the log sheet immensely. Is this possible?
I've got this record code on the script editor:
function RECORD_HISTORY[] {
var historySheetName = "HISTORY";
var historySheet = getSheetWithName[historySheetName];
if [historySheet == null] {
historySheet = SpreadsheetApp.getActiveSpreadsheet[].insertSheet[historySheetName, 1];
}
range = historySheet.getRange[2, 1, 1, 9];
var values = range.getValues[];
values[0][0] = new Date[];
historySheet.appendRow[values[0]];
}
function getSheetWithName[name] {
var sheets = SpreadsheetApp.getActiveSpreadsheet[].getSheets[];
for [var idx in sheets] {
if [sheets[idx].getName[] == name] {
return sheets[idx];
}
}
return null;
}
I know there's at least one function that has the power to edit groups etc:
shiftRowGroupDepth[]
All the examples of this function were used in different situations so I couldn't figure out how to go about using this function for my needs. You guys have any idea how to go about to doing this?
Here's a dummy file for you to have a better idea of my log sheet: //docs.google.com/spreadsheets/d/1ExXtmQ8nyuV1o_UtabVJ-TifIbORItFMWjtN6ZlruWc/
EDIT: I want this sheet / script to do everything automatically so neither I or the user need to open the sheet and group rows manually. I don't even want to open the file in order to press a button that calls a function that groups rows. What I want is a way or script that automatically creates groups of rows by month with its own row with the name of the month: AUGUST etc. and then within/below that row/group the days, and within these day groups, the rest of the rows with the hourly logs. This row grouping function should happen automatically, while the file is closed, and the data is being recorded to the log by the function that records data which is called through a time trigger.
I want the user to have no role whatsoever in handling information, grouping etc. The user should just open the spreadsheet in order to be able to get an easy fast interpretation of the data, and be able to navigate it easily.
Also I would like the rows to be automatically collapsed after they are created and not remain expanded because if would confuse the user.
Finally would this be easier to do if the code was combined with the recording function I wrote? "RECORD_HISTORY[]"
Let me know if this was clear enough. Regarding the time zone, mine is GMT+01:00.
Thanks!