r/GoogleAppsScript • • Jan 16 '23

Question Exception: The parameters (String,number) don't match the method signature for SpreadsheetApp.Spreadsheet.getRange.

Hi,

I just started using apps script today and i have issues with my script (i never used JS before) i'm trying to use it for google sheet and use variables in a getRange function.

But, as you can see in the title, i can't.

Here is the function i use

var i = 2
var y = 2
var spreadsheet = SpreadsheetApp.getActive();
var nom = spreadsheet.getRange(21,i).getValues();
var ctrl = = spreadsheet.getRange(3, y).getValues();
while (nom = ctrl) 
{
    ctrl = spreadsheet.getRange(3, y).getValues();
    var test = spreadsheet.getRange(8, y).getValues();
    const result = /^test/.test(test)
    if (result = true) 
    {
        var valeur var valeur = spreadsheet.getRange(8, y);
        spreadsheet.getRange(22, i).setValue(valeur)
    }
} 

Please, tell me what's wrong, i can't figure. The debugger tells me the error is in this line "var nom = spreadsheet.getRange(21,i).getValues();" i'm pretty sure there is more mistakes nonetheless.

xoxo

6 Upvotes

7 comments sorted by

1

u/mjbrusso Jan 16 '23

SpreadsheetApp.getActive() method returns the currently active spreadsheet, not a Sheet object. Change this line to var spreadsheet = SpreadsheetApp.getActiveSheet();

You also have an error here, where you are using the assignment operator:

if (result = true)

Change to:

if (result)

1

u/L0fvvyr Jan 16 '23

Thanks, i think i understood, i mistook the active spreadsheet and the sheet object.

2

u/whale_why_not May 29 '24

I know you commented this a year ago, but you seriously just saved my ass. One of those "I've been staring at my code for too long" moments. Thank you!!!!!!!!!

1

u/gothamfury Jun 28 '24

Thanks to OP and this response. Definitely helped me in a similar situation.

1

u/mjbrusso Jan 16 '23

In addition, remove the duplicated var valeur

1

u/whale_why_not May 29 '24

One year later but I found this post because I was having the exact same issue and googled the error after struggling for so long. Thank you for posting this a year ago and saving my sanity by finding a solution.

0

u/[deleted] Jan 16 '23

[deleted]

1

u/Ebubekir97 May 23 '23

Hello, I have a question about Google Apps Script. Can you help?