I want to create a way to hide a certain number of rows if there is a certain value in a cell of a Google spreadsheet.
A B
1 Include All options`? Yes/No
2 Option A: Yes/No
3 Option B: Yes/no
etc.
If cell B1 is "yes" there is no need to look at all other options. However, if they select "No", there needs to be an option for selecting the Option "Yes/No". For this reason, I would like to hide the rows when option = yes but unhide them if it is No
This code detects whether a certain cell (B3) was edited, then hides a couple of rows under that row (row 3) if it was edited:
function onEdit(e) {
Logger.log('e.value: ' + e.value);
var cellEdited = e.range.getA1Notation();
Logger.log('cellEdited: ' + cellEdited);
if (cellEdited === "B3") {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var theSheet = ss.getActiveSheet();
theSheet.hideRows(4, 2);
};
}
This code uses a function name of onEdit()
, which means that it monitors the spreadsheet for edits to a cell. If there is an edit, the function runs. This is a "simple" trigger. There are also installable triggers for monitoring the spreadsheet.
Note the Logger.log()
statements. These statement print information to the LOGS which you can VIEW from the VIEW, LOGS menu.
function onEdit(e) {
Logger.log('e.value: ' + e.value);
var cellEdited = e.range.getA1Notation();
Logger.log('cellEdited: ' + cellEdited);
if (cellEdited === "B1" && e.value === "yes") {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var theSheet = ss.getActiveSheet();
theSheet.hideRows(2, 2);
};
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.