Very Stupid Question Regarding .getRange()

Viewed 31

I am really sorry.. this is probably going to be the dumbest question you have seen in a good long time, if not ever... LOL I have been pulling my hair out on this for two hours and for the life of me I can't figure out what I am doing wrong...

This is stupid simple. It is a simple SpreadsheetApp.getRange() using the alternate parameters instead of your the usual "A1" reference. I am sure I am screwing up the syntax, but for the life of me I can't seem to figure out or find what it is that I am doing wrong...

This ties in with a larger project, of course, but for the sake of simplicity, this is what I currently have:

function test() {
  var teamSheet = SpreadsheetApp.getActive();
  teamSheet.getRange("25,25").activate();
  teamSheet.getCurrentCell().setValue("Stuff");
};

All I want it to do there is go to Y25 and put in the word "Stuff". This is eventually going to end up in a loop where both the Row and Column values are increasing with each iteration - hence why I am using the alternate parameters instead of just entering "Y25".

I have tried in single quotes, double quotes, no quotes, square brackets, R[25]C[25], on and on... The error message I am getting is either Exception: Range not found or Exception: The parameters (String,number) don't match the method signature for SpreadsheetApp.Spreadsheet.getRange.

I appreciate this is a bit of a waste of your time and I am likely making some stupid, silly mistake - but I don't see it and I am loosing my mind on this... Please help!!

1 Answers

The script you provide always goes to A25 because the current cell of an active range is always the upper left corner. It's the same as this one.

function test() {
  const ss = SpreadsheetApp.getActive();
  ss.getRange("25:25").activate()
  ss.getCurrentCell().setValue("A25");
};

I don't understand why you would want to but you could right it like this:

function test() {
  const ss = SpreadsheetApp.getActive();
  ss.getRange("Y25:25").activate()
  ss.getCurrentCell().setValue("Y25");
};

And then it would go to Y25 and put "Y25" there or just as easily

function test() {
  const ss = SpreadsheetApp.getActive();
  ss.getRange("Y25").activate()
  ss.getCurrentCell().setValue("Stuff");
};

If this does not answer your question let me know. Perhaps you should ask it in the context of how you wish to apply it.

Related