Reputation: 33
Appreciate if someone can help me out with this chunk of codes. What I am trying to achieve (step by step) is:
This is my 1st time doing coding....really grateful if a kind soul can help. Thanks.
function showHide() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("sheet1");
var sheet2 = ss.getSheetByName("sheet2");
var vtrue = "TRUE"
var vfalse = "FALSE"
sheet1.getRange('A7').activate();
if (sheet1.getRange('A7').getValue() == vtrue) {
sheet2.showColumns(sheet2.getRange("P:AA"));
} else if (sheet1.getRange('A7').getValue() == vfalse) {
sheet2.hideColumns(sheet2.getRange("P:AA"));
}
}
Thanks a million.
Cheers.
Upvotes: 1
Views: 5056
Reputation: 33
Thanks everyone for the tips! It helped. I have finally gotten the function working.
function showHide() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss.getSheetByName("sheet1");
var sheet2 = ss.getSheetByName("sheet2");
sheet1.getRange('A7').activate();
if (sheet1.getRange('A7').getValue() == true) {
sheet2.showColumns(16,2);
} else {
sheet2.hideColumns(16,2);
}
}
Instead of getting var result from checkbox, it is already a boolean. Nosyara is right, the showColumns() API require number parameters to indicate the column(s) to hide or show.
Many thanks again!
Upvotes: 2
Reputation: 2751
The right API to hide columns is sheet2.hideColumns(columnIndex, numOfColumns)
- both parameters are numbers.
You can see it here .
There is good trick to learn how thinks works.
Upvotes: 2