2

I'm trying to follow this YouTube tutorial and it has already what I specifically need. It's a tutorial on GOOGLE SHEET - APPS SCRIPT. I'm trying to get the ROW NUMBER from a specified range. It's just that my data range of reference is vertical instead of horizontal. But when I try to edit the code, it returns an error value of -1. Could someone help me with this?

Here is the YouTube link that I am following: https://www.youtube.com/watch?v=1SIN5NyQ9fw&t=926s

Here's what I currently have. And if I understand correctly, the problem should be within lines 18 and 19 (see below). I could be wrong though.

var makes = datass.getRange( 2, 2, datass.getLastRow(), 1).getValues();

var makeIndex = makes[0].indexOf(activeCell.getValue());

Will appreciate the help! Thanks so much!!

function myFunction() {

  var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();


  
}

function onEdit(){

var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ITEMS"); 

var activeCell = ss.getActiveCell();

if(activeCell.getColumn() == 2 && activeCell.getRow() > 1){

  var makes = datass.getRange( 2, 2, datass.getLastRow(), 1).getValues();
  var makeIndex = makes[0].indexOf(activeCell.getValue());



  Logger.log(activeCell.getValues());
  Logger.log(makes[0]);
  Logger.log(makeIndex);


ss.getRange("E10").setValue(makeIndex);

}


}
TheMaster
  • 45,448
  • 6
  • 62
  • 85
mr.dan
  • 21
  • 1
  • `var makeIndex = datass.getRange( 2, 2, datass.getLastRow(), 1).getValues().flat().indexOf(activeCell.getValue())` – TheMaster Jun 20 '22 at 15:10

1 Answers1

0

Hmm here you are asking if the active cell column is 2, but next in getRange function you put numColumns to 1. Maybe try to put datass.getLastColumn() instead of 1 so the code looks like:

 var makes = datass.getRange( 2, 2, datass.getLastRow(), datass.getLastColumn()).getValues();