下拉以根据下拉菜单隐藏行

时间:2018-08-20 16:45:37

标签: google-apps-script google-sheets triggers

在Google表格中,当我在R4的下拉菜单中显示 BLS 时,我想隐藏第 5到31 行,并在{{1} }是空白或说 ALS

这是我最近的尝试:

R4

我也尝试过这种方法,它指向我记录的2个不同的宏,但是这会使屏幕发疯,并且每当编辑其他内容时就会跳转:

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getSheetByName("Shee1");
  var rg = sh.getDataRange();
  var vA = rg.getValues();
  var R4 = sh.getRange("R4").getValue();
  for (var i = 0; i < vA.length; i++) {
    var row = i + 1;
    switch (R4) {
      case "BLS":
        if (row >= 5 && row <= 31) {
          sh.hideRows(row);
        }
        break;
      case "ALS":
        if (row >= 4 && row <= 32) {
          sh.showRows(row);
        }
        break;
      default:
    }
  }
}

1 个答案:

答案 0 :(得分:0)

function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Sheet1");           // Enter sheet name
var row = s.getRange('R:R').getValues(); 
// Enter column letter that has the      text "hide" and  "unhide"

s.showRows(1, s.getMaxRows());
for(var i=0; i< row.length; i++){ if(row[i] == 'hide') { s.hideRows(i+1, 27); } 
else if(row[i] == 'unhide'){ s.unhideRow(ss.getDataRange()); } 
}
}