Home > Mobile >  I'm keep getting an error that says the column of the range is too small
I'm keep getting an error that says the column of the range is too small

Time:02-11

I was writing some code and when i tried to run it I got an error The starting column of the range is too small. Which I honestly don't know what that means.

I'm using google app script

The error I'm getting is on this line

var cellCup = ss.getRange(ctCup, 0).activate().getValue();

const ss = SpreadsheetApp.openByUrl(THIS).getSheetByName('WP_Data');
var ctCup =114;
var cellCup = ss.getRange(ctCup, 0).activate().getValue();

But it works here

    var ctMHS = 3;
    var cellMHS = ss.getRange('A3');
    while ( cellMHS.offset(ctMHS, 0).getValue() != "" ) {
      ctMHS  ;
    }

This is my first question so I'm honestly not sure if im supposed to povide more info. please let me know

Thank you.

CodePudding user response:

According to Google App Script docs https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column

The column index of the cell to return; column indexing starts with 1.

This should fix your problem:

var cellCup = ss.getRange(ctCup, 1).activate().getValue();

CodePudding user response:

As answered by Kostas, the column and row indices for .getRange() should start at 1.

The reason this snippet works with a 0 index:

cellMHS.offset(ctMHS, 0).getValue()

is that the .offset() method is different from the .getRange() method: .offset() doesn't expect an absolute cell or row index: its arguments are offsets relative to the range represented by cellMHS, i.e. how far away from that range. So a value of 0 just means use the same column as the original range. You can even pass a negative offset to reference a column to the left of cellMHS.

CodePudding user response:

If you are using Visual Studio Code try to reopen the Program because it happened to me to so its kinda of a glitch.

  • Related