1
votes

I'm following along with this basic tutorial, and my code looks similar, but I can't figure out why it's not working exactly. setValue inserts the value from A1 into each cell of the destination range, instead of inserting an array (nameRange) which Logger.log confirms is there.

https://www.youtube.com/watch?v=v1nvDkDY-3g

sheet1: basic sample data

           colA     colB   colC       
 row1     Name     Val1   Val2
 row2     jake      2        3
 row3     andrew    1        0
 row4     allie     4        0

Script:

  var app = SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getActiveSheet();
  var lastRow = activeSheet.getLastRow();

function fillDownFormula(){

    var nameRange = activeSheet.getRange(1,1,lastRow).getValues(); 
    Logger.log(guideRange);  
        //shows [[Name], [jake], [andrew], [allie]]

    activeSheet.getRange("D1:D5").setValue(guideRange);
    //writes 'Name' to each cell in this range

}
1

1 Answers

1
votes

How about this modification?

Modification points :

  • guideRange is not used in your script.
    • Please modify this to nameRange.
  • At getRange("D1:D5").setValue(nameRange), setValue() import 1st element which is "Name" to "D1:D5".
    • Please modify setValue() to setValues()
    • And for the range, modify "D1:D5" to "D1:D4".
      • Because the number of rows of nameRange is 4, "D1:D4" is used.

The modified script is as follows.

From :

activeSheet.getRange("D1:D5").setValue(guideRange);

To :

activeSheet.getRange("D1:D4").setValues(nameRange);

If I misunderstand your question, I'm sorry.