arcadianrhythm
arcadianrhythm

Reputation: 69

Why does Google App Script getRange think I'm giving it a class instead of a number?

I'm trying to write a script that copies some data from one sheet and puts it in another sheet. For some reason the line toAppend[i] = projectSheet.getRange(rowsToCheck[i], projectColumn).getValue(); causes an error: "Cannot find method getRange((class),number)." Why is this happening? If rowsToCheck is an array of numbers, shouldn't rowsToCheck[i] be a number, not a class? I'm especially confused because I haven't created any classes in my code. How can I get getRange() to treat rowsToCheck[i] as a number? Relevant code is below. EDIT: I even did console.log(typeof rowsToCheck[0]) and it returned "number" so what gives?

var textFinder = projectSheet.createTextFinder("Cumulative Actuals");
var rowSearch = textFinder.findNext().getRow();
//making an array of rows to check (skipping over some data that I don't want to copy over)
for(var i = 0; i<=8; i++){
    if(projectSheet.getRange(rowSearch, projectColumn).isBlank()){
      for(var j = 0; j<4; j++){
        rowSearch++; 
      }
    }
    else{
      rowsToCheck.push(rowSearch);
      rowSearch++;
    }
  }

  for(i=0; i<=rowsToCheck.length; i++){
    toAppend[i] = projectSheet.getRange(rowsToCheck[i], projectColumn).getValue();
  }

Upvotes: 0

Views: 44

Answers (1)

Tanaike
Tanaike

Reputation: 201428

I think that the reason of your issue might be for(i=0; i<=rowsToCheck.length; i++){. When i becomes to rowsToCheck.length, rowsToCheck[i] returns undefined. When rowsToCheck[i] is undefined, such error occurs. So how about the following modification?

From:

for(i=0; i<=rowsToCheck.length; i++){

To:

for(i=0; i<rowsToCheck.length; i++){

Upvotes: 2

Related Questions