Home > Enterprise >  Copying content to another cell when 'Check-Box' is checked
Copying content to another cell when 'Check-Box' is checked

Time:10-05

I am trying to move the content from one table to another field within one sheet when the checkbox is checked. Currently, I have fiddled around and got the checkbox within a range to act like a radio button but have had no luck trying to figure out how to copy the content to another cell. Is there a way to do it?

https://docs.google.com/spreadsheets/d/1fLpPZro_8olt4ASEhIMyzSjjvPeeTlqKlIvAWF4eamk/edit?usp=sharing

*function onEdit(event) {
 // Select only one checkbox
    try {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = event.range.getSheet();
  
    if( sheet.getName() === 'Sheet1' ) { 
    if( event.range.getColumn() === 4 ) { 
      var range = sheet.getRange(4,4,3,1);
      var checks = range.getValues();
      var valid = range.getDataValidations();
      for( var i=0; i<checks.length; i   ) { 
        if( valid[i][0].getCriteriaType() === SpreadsheetApp.DataValidationCriteria.CHECKBOX ) 
  checks[i][0] = false;
      }
      range.setValues(checks);
      event.range.setValue(event.value);
      if( event.value === true ) {
        event.source.getSheetByName('Sheet1').getRange(4,4,3,1).setValue(event.range.getRow());
      }
    }
  }
}
catch(err) {
  SpreadsheetApp.getUi().alert(err);   
  }
}*

CodePudding user response:

Ticking a checkbox will return True as a boolean value.

You could use the script below to do the function that you would like to do. I've included the solution for one of the row, for the other rows you just need to add a few more if statement in the block.

function onEdit(e){
var xyz = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet11");
if (xyz.getRange("D4").getValue() == true){
var name = xyz.getRange("B4").getValue()
var phone = xyz.getRange("C4").getValue()
xyz.getRange("G4").setValue(name)
xyz.getRange("G5").setValue(phone)
}
else {
  xyz.getRange("G4").clearContent()
xyz.getRange("G5").clearContent()
}    
}

Remember to upvote if this helps you. :)

  • Related