0

I just want to change a cell in E5 but I can only seem to edit the first column.

var cell = sheet.getRange(2,5)
    cell.setValue("TEXT");

All this does is put "TEXT" into cell E2.

EDIT: Below is the entire code.

var sheet = SpreadsheetApp.openById("SheetID").getSheetByName('Sheet1');

function doGet(e) {
  
  var amount = JSON.parse(e.parameter.amount)

  var student = JSON.parse(e.parameter.student)

var cell = sheet.getRange(student,2)

cell.setValue(amount);
}

SAMPLE URL https://script.google.com/macros/s/mygooglesheetID/exec?amount=6&student=6

Dylan
  • 1
  • 3
  • If your script is really adding `TEXT` TO A2 then the code included in the question is not the one that does that. If the current answer doesn't help please add a [mcve]. – Rubén May 28 '21 at 16:59
  • Ok, I've edited my post to include all code. – Dylan May 28 '21 at 17:39
  • Please add the a sample URL showing the parameter values that are sent in your tests. – Rubén May 28 '21 at 17:41
  • have you tried using A1notation on getRange() to make sure that everytime you setValue(), it always goes to the first column? – Jason E. May 28 '21 at 18:27
  • I've tried to use A1 notation but couldn't figure it out. I tried: var range = SpreadsheetApp.getActiveSpreadsheet().getRange("A1:H8"); var values = range.getValues(); values[6][3] = "This is D7"; values[5][6] = "This is G6"; range.setValues(values); – Dylan May 29 '21 at 12:20

1 Answers1

1

The code in the question should is adding TEXT to E2 but you want to be added to E5.

The first parameter is the row, the second is the column, so in order to get E5

instead of

var cell = sheet.getRange(2,5) 

use

var cell = sheet.getRange(5,5);

Regarding the full code

instead of

var cell = sheet.getRange(student,2)

use

var cell = sheet.getRange(student,5)

Reference

NOTE: As a good practice, include a semicolon (;) at the end of the JavaScript statements.

Rubén
  • 34,714
  • 9
  • 70
  • 166
  • Even when I use (2,5), the "TEXT" appears in the first column. So regardless, it's still not getting out of the 1st column. – Dylan May 28 '21 at 16:49
  • I didn't suggested to use `(2,5)`. Please read carefully my answer. – Rubén May 28 '21 at 16:51
  • I don’t think you read my initial post correctly or maybe I was unclear. My original code SHOULD put TEXT into E2, but INSTEAD it puts it into A2. – Dylan May 28 '21 at 17:10
  • Edited your question to replace `B5` by `E5` and `A2` by `E2` and edited my answer accordingly. If the changes to the question doesn't reflect what you are looking please edit the question including a [mcve]. – Rubén May 28 '21 at 17:39