I'm trying to create an "intake form" as part of a google sheet that will show or hide rows and columns based on selection in different dropdowns:
Hide/show column on other sheet depending on selection in dropdown.
- If dropdown selection in "NamedRange1" is "A", show column 3 on other sheet;
- In all other cases (i.e. when blank or "B"), hide column 3 on other sheet;
Hide/show rows on same sheet depending on selection in dropdown.
- If dropdown in "NamedRange2" is "Yes", show rows 15-19
- In all other cases (i.e. when blank or "No), hide rows 15-19
Same as above but different dropdown and rows.
- If dropdown in in "NamedRange3" "is "Yes", show rows 26-40
- In all other cases (i.e. when blank or "No), hide rows 26-40
So far I can get nr. 1 to work, but not 2 or 3... Additionally, I can't get them to run automatically on edit of the form...
I'm pretty new to all of this, so any help would be much appreciated :-)
This is my code so far:
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Start Here >>")
}
function HideColumns() {
var ss = SpreadsheetApp.getActive();
var name = ss.getRangeByName("NamedRange1");
var namevalue = name.getValue();
if (namevalue == "A") {
var sheet = ss.getSheetByName("Sheet 2");
sheet.showColumns(3);
}
else if (namevalue != "A") {
var sheet = ss.getSheetByName("Sheet 2");
sheet.hideColumns(3);
}
}
function HideRows() {
var ss = SpreadsheetApp.getActive();
var name = ss.getRangeByName("NamedRange2");
var namevalue = name.getValue();
if (namevalue == "Yes") {
var sheet = ss.getSheetByName("Sheet1");
sheet.showRows(15, 10);
}
else if (namevalue != "Yes") {
var sheet = ss.getSheetByName("Sheet1");
sheet.hideRows(15, 10);
}
}
function HideRows() {
var ss = SpreadsheetApp.getActive();
var name = ss.getRangeByName("NamedRange3");
var namevalue = name.getValue();
if (namevalue == "Yes") {
var sheet = ss.getSheetByName("Sheet1");
sheet.showRows(26, 15);
}
else if (namevalue != "Yes") {
var sheet = ss.getSheetByName("Sheet1");
sheet.hideRows(26, 15);
}
}