简体   繁体   中英

Google Sheets formula to change a cells value based on another cells value

I am currently muddled while trying to create a formula within Google Sheets that basically says:

"If the value of cell E10 equals "Levy" then change the value of E11 cell to"Monthly" , if E10 equals anything other than "Levy" change the value of E11 to a drop down of menu "Triannual" and"Quarterly"*

This is the formula I have so far which gets the first part done. I'm just stuck with creating the formula to create the drop down of the two other options if E10 = something other than the specified value.

= IF(E10 = "Levy","Monthly","Triannual")

What else would I need to add?

Best Regards.

This should do it. Copy this to your script editor and save it:

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  var s=ss.getActiveSheet()
  var nota=e.range.getA1Notation()
  if(nota=="E10"){
  var val=e.range.getValue()
    if(val=="Levy"){
      s.getRange("E11").setDataValidation(null)
      s.getRange("E11").setValue("Monthly")
  }
      else{
  s.getRange('E11').clearContent()      
  var cell = s.getRange('E11');
  var rule = SpreadsheetApp.newDataValidation().requireValueInList(['Triannual', 'Quarterly']).build();
  cell.setDataValidation(rule);
   }}}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM