0

I am trying to write a custom script that is bound to my Google spreadsheet. I want to trigger it using onEdit(e) based on the value changing in the dropdown located in B3 of 'Pax Split Sheet'.

I had it working in a limited way, but it was causing problems because the custom function was running whenever B3 was edited in any sheet, not just 'Pax Split Sheet'!B3.

I switched the onEdit to a normal function for testing and also added a couple of if statements to first check that both the sheet name and the active cell are correct, but I'm now getting the following error message:

TypeError: activeSheet.getRange.getA1Notation is not a function

Here is a sample of the code up to where it errors:

function hltcells(){

  var activeSheet = SpreadsheetApp.getActiveSheet();
  var sheetNameTest = activeSheet.getSheetName();

  if (activeSheet.getSheetName() == 'Pax Split Sheet'){
    
    if (activeSheet.getRange.getA1Notation() === 'B3'){
1

1 Answer 1

0

onEdit(e): Sheet Name & Range

Simple onEdit(e) trigger that verifies the edited range and the sheet name

function onEdit(e) {
   
  if ((e.range.getA1Notation() == "B3") &&
      (e.range.getSheet().getSheetName() == "Sheet1")){
      
    Logger.log("Action Performed!");
  
  }

}

Resources:

Equivalent script that first stores values in variables

function onEdit(e) {

  const matchCell="B3";
  const matchName="Sheet1";
  
  const range=e.range;
  const cell=range.getA1Notation();
  const sheet=range.getSheet();
  const name=sheet.getSheetName();
 
  if ((cell == matchCell) && (name == matchName)){
      
    Logger.log("action performed");
  
  } 

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.