热卖商品
新闻详情
google apps script - Clear a cell when a certain value of a dropdown list is selected - Stack Overflow
来自 :
发布时间:2025-01-15
Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.Learn more
I would need to fix my script \"code\" so that when \"-\", \"--\" or \"---\" values are selected from the dropdown list, the cells controlled by the script are cleared.
Here\'s the link of the Google Sheets:
https://docs.google.com/spreadsheets/d/1ZmmqPgH2lNC_eYivkYcKQrNH8BdM-g3z-ZVK5ePgxnM/edit?usp=sharing
The code:
function onEdit(e) { var ss=e.source; var rg=e.range;var sh=rg.getSheet(); if(rg.columnStart!=2 rg.columnStart!=10 rg.columnStart!=18 rg.columnStart!=26 rg.columnStart!=34){return;} setClearOnNoValue(e);function setClearOnNoValue(e) { var rg=e.range; var sh=rg.getSheet(); if(e.value e.value.length 0) {//added e.value.length 0 sh.getRange(rg.rowStart, rg.columnStart + 3).setValue(Utilities.formatDate(new Date(new Date().getFullYear(),new Date().getMonth()+1,new Date().getDate(),new Date().getHours(),new Date().getMinutes()),Session.getScriptTimeZone(),\"d/MMM/yyyy HH:mm\")); }else{ sh.getRange(rg.rowStart, rg.columnStart + 3).setValue(\'\'); Please post some of the code you are referring to. Just linking to your code somewhere is not encouraged on SO. minimal reproducible example Chris Feb 12 \'19 at 18:14 var name=sh.getName(); if(rg.columnStart!=2 rg.columnStart!=10 rg.columnStart!=18 rg.columnStart!=26 rg.columnStart!=34){return;} setClearOnNoValue(e);function setClearOnNoValue(e) { var rg=e.range; var sh=rg.getSheet(); if((e.value e.value.length 0)) {//added e.value.length 0 sh.getRange(rg.rowStart, rg.columnStart + 3).setValue(Utilities.formatDate(new Date(new Date().getFullYear(),new Date().getMonth()+1,new Date().getDate(),new Date().getHours(),new Date().getMinutes()),Session.getScriptTimeZone(),\"d/MMM/yyyy HH:mm\")); }else{ sh.getRange(rg.rowStart, rg.columnStart + 3).setValue(\'\'); if((e.value e.value==\'-\')||(e.value e.value==\'--\')||(e.value e.value==\'---\')) { sh.getRange(rg.rowStart, rg.columnStart + 3).setValue(\'\');site design / logo 2020 Stack Exchange Inc; user contributions licensed under cc by-sa. rev2020.5.18.36843 Stack Overflow works best with JavaScript enabled本文链接: http://list.immuno-online.com/view-1510733714.html
发布于 : 2025-01-15
阅读()
最新动态
1970-01-02
2015-01-06
2016-02-03
2016-09-02
2017-04-03
2017-09-23
2017-11-15
2021-05-24
2018-01-28
2018-04-07
联络我们