How to declare a variable range to a spreadsheet in google scripts
I can't set a variable to return the number to the last row under the K column in google sheets. The code fails on the last line - .setValues(exampleText) where I have already defined exampleText as a variable.
I have used different methods of setting variables including setting a variable for a column.
I get the following error: "Cannot find method getRange(number,number)."
The following code works solved by @TheMaster
var ss = SpreadsheetApp.getActiveSpreadsheet()
var column = 11
var lastRow = ss.getLastRow();
range = ss.getActiveSheet().getRange(lastRow,column);
range.setValue(exampletext)
google-apps-script
|
show 7 more comments
I can't set a variable to return the number to the last row under the K column in google sheets. The code fails on the last line - .setValues(exampleText) where I have already defined exampleText as a variable.
I have used different methods of setting variables including setting a variable for a column.
I get the following error: "Cannot find method getRange(number,number)."
The following code works solved by @TheMaster
var ss = SpreadsheetApp.getActiveSpreadsheet()
var column = 11
var lastRow = ss.getLastRow();
range = ss.getActiveSheet().getRange(lastRow,column);
range.setValue(exampletext)
google-apps-script
1
getRange(row,column)
type syntax only accepts numbers NOT strings.
– TheMaster
Dec 31 '18 at 12:43
You need to review the method signatures. These appear in the autocomplete popup (while writing code in the editor) and have more detail explained on the reference documentation website (use the Help menu).
– tehhowch
Dec 31 '18 at 12:55
I have edited my code to include column = 11 and replaced k with column but still doesn't work. I don't understand why? @TheMaster I have already checked documentation before posting but don't know how to proceed.
– Jonathan Harker
Dec 31 '18 at 12:59
3
OnlygetRange(string)
is available onSpreadsheet
(ss). So, you can usess.getRange('Sheet1!A1:B4')
.getRange(number,number)
is only available on sheet.ss.getActiveSheet().getRange(1,4)
– TheMaster
Dec 31 '18 at 13:42
1
Thanks @TheMaster I'm new at interacting here - I'll keep these points in mind for next time - have a great day.
– Jonathan Harker
Jan 1 at 13:06
|
show 7 more comments
I can't set a variable to return the number to the last row under the K column in google sheets. The code fails on the last line - .setValues(exampleText) where I have already defined exampleText as a variable.
I have used different methods of setting variables including setting a variable for a column.
I get the following error: "Cannot find method getRange(number,number)."
The following code works solved by @TheMaster
var ss = SpreadsheetApp.getActiveSpreadsheet()
var column = 11
var lastRow = ss.getLastRow();
range = ss.getActiveSheet().getRange(lastRow,column);
range.setValue(exampletext)
google-apps-script
I can't set a variable to return the number to the last row under the K column in google sheets. The code fails on the last line - .setValues(exampleText) where I have already defined exampleText as a variable.
I have used different methods of setting variables including setting a variable for a column.
I get the following error: "Cannot find method getRange(number,number)."
The following code works solved by @TheMaster
var ss = SpreadsheetApp.getActiveSpreadsheet()
var column = 11
var lastRow = ss.getLastRow();
range = ss.getActiveSheet().getRange(lastRow,column);
range.setValue(exampletext)
google-apps-script
google-apps-script
edited Dec 31 '18 at 13:51
Jonathan Harker
asked Dec 31 '18 at 12:16
Jonathan HarkerJonathan Harker
76
76
1
getRange(row,column)
type syntax only accepts numbers NOT strings.
– TheMaster
Dec 31 '18 at 12:43
You need to review the method signatures. These appear in the autocomplete popup (while writing code in the editor) and have more detail explained on the reference documentation website (use the Help menu).
– tehhowch
Dec 31 '18 at 12:55
I have edited my code to include column = 11 and replaced k with column but still doesn't work. I don't understand why? @TheMaster I have already checked documentation before posting but don't know how to proceed.
– Jonathan Harker
Dec 31 '18 at 12:59
3
OnlygetRange(string)
is available onSpreadsheet
(ss). So, you can usess.getRange('Sheet1!A1:B4')
.getRange(number,number)
is only available on sheet.ss.getActiveSheet().getRange(1,4)
– TheMaster
Dec 31 '18 at 13:42
1
Thanks @TheMaster I'm new at interacting here - I'll keep these points in mind for next time - have a great day.
– Jonathan Harker
Jan 1 at 13:06
|
show 7 more comments
1
getRange(row,column)
type syntax only accepts numbers NOT strings.
– TheMaster
Dec 31 '18 at 12:43
You need to review the method signatures. These appear in the autocomplete popup (while writing code in the editor) and have more detail explained on the reference documentation website (use the Help menu).
– tehhowch
Dec 31 '18 at 12:55
I have edited my code to include column = 11 and replaced k with column but still doesn't work. I don't understand why? @TheMaster I have already checked documentation before posting but don't know how to proceed.
– Jonathan Harker
Dec 31 '18 at 12:59
3
OnlygetRange(string)
is available onSpreadsheet
(ss). So, you can usess.getRange('Sheet1!A1:B4')
.getRange(number,number)
is only available on sheet.ss.getActiveSheet().getRange(1,4)
– TheMaster
Dec 31 '18 at 13:42
1
Thanks @TheMaster I'm new at interacting here - I'll keep these points in mind for next time - have a great day.
– Jonathan Harker
Jan 1 at 13:06
1
1
getRange(row,column)
type syntax only accepts numbers NOT strings.– TheMaster
Dec 31 '18 at 12:43
getRange(row,column)
type syntax only accepts numbers NOT strings.– TheMaster
Dec 31 '18 at 12:43
You need to review the method signatures. These appear in the autocomplete popup (while writing code in the editor) and have more detail explained on the reference documentation website (use the Help menu).
– tehhowch
Dec 31 '18 at 12:55
You need to review the method signatures. These appear in the autocomplete popup (while writing code in the editor) and have more detail explained on the reference documentation website (use the Help menu).
– tehhowch
Dec 31 '18 at 12:55
I have edited my code to include column = 11 and replaced k with column but still doesn't work. I don't understand why? @TheMaster I have already checked documentation before posting but don't know how to proceed.
– Jonathan Harker
Dec 31 '18 at 12:59
I have edited my code to include column = 11 and replaced k with column but still doesn't work. I don't understand why? @TheMaster I have already checked documentation before posting but don't know how to proceed.
– Jonathan Harker
Dec 31 '18 at 12:59
3
3
Only
getRange(string)
is available on Spreadsheet
(ss). So, you can use ss.getRange('Sheet1!A1:B4')
. getRange(number,number)
is only available on sheet. ss.getActiveSheet().getRange(1,4)
– TheMaster
Dec 31 '18 at 13:42
Only
getRange(string)
is available on Spreadsheet
(ss). So, you can use ss.getRange('Sheet1!A1:B4')
. getRange(number,number)
is only available on sheet. ss.getActiveSheet().getRange(1,4)
– TheMaster
Dec 31 '18 at 13:42
1
1
Thanks @TheMaster I'm new at interacting here - I'll keep these points in mind for next time - have a great day.
– Jonathan Harker
Jan 1 at 13:06
Thanks @TheMaster I'm new at interacting here - I'll keep these points in mind for next time - have a great day.
– Jonathan Harker
Jan 1 at 13:06
|
show 7 more comments
1 Answer
1
active
oldest
votes
getRange
is a method that's available both on Spreadsheet class and Sheet class.
However, only getRange(string)
is available on Spreadsheet(ss). So, you can use ss.getRange('Sheet1!A1:B4')
.
And getRange(number,number)
is only available on sheet. So, You can use ss.getActiveSheet().getRange(1,4)
. Sheet class also accepts other variations of this method, but Spreadsheet class doesn't, which only accepts string as the only parameter.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987422%2fhow-to-declare-a-variable-range-to-a-spreadsheet-in-google-scripts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
getRange
is a method that's available both on Spreadsheet class and Sheet class.
However, only getRange(string)
is available on Spreadsheet(ss). So, you can use ss.getRange('Sheet1!A1:B4')
.
And getRange(number,number)
is only available on sheet. So, You can use ss.getActiveSheet().getRange(1,4)
. Sheet class also accepts other variations of this method, but Spreadsheet class doesn't, which only accepts string as the only parameter.
add a comment |
getRange
is a method that's available both on Spreadsheet class and Sheet class.
However, only getRange(string)
is available on Spreadsheet(ss). So, you can use ss.getRange('Sheet1!A1:B4')
.
And getRange(number,number)
is only available on sheet. So, You can use ss.getActiveSheet().getRange(1,4)
. Sheet class also accepts other variations of this method, but Spreadsheet class doesn't, which only accepts string as the only parameter.
add a comment |
getRange
is a method that's available both on Spreadsheet class and Sheet class.
However, only getRange(string)
is available on Spreadsheet(ss). So, you can use ss.getRange('Sheet1!A1:B4')
.
And getRange(number,number)
is only available on sheet. So, You can use ss.getActiveSheet().getRange(1,4)
. Sheet class also accepts other variations of this method, but Spreadsheet class doesn't, which only accepts string as the only parameter.
getRange
is a method that's available both on Spreadsheet class and Sheet class.
However, only getRange(string)
is available on Spreadsheet(ss). So, you can use ss.getRange('Sheet1!A1:B4')
.
And getRange(number,number)
is only available on sheet. So, You can use ss.getActiveSheet().getRange(1,4)
. Sheet class also accepts other variations of this method, but Spreadsheet class doesn't, which only accepts string as the only parameter.
edited Jan 1 at 9:23
answered Jan 1 at 9:17
TheMasterTheMaster
10.4k3836
10.4k3836
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53987422%2fhow-to-declare-a-variable-range-to-a-spreadsheet-in-google-scripts%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
getRange(row,column)
type syntax only accepts numbers NOT strings.– TheMaster
Dec 31 '18 at 12:43
You need to review the method signatures. These appear in the autocomplete popup (while writing code in the editor) and have more detail explained on the reference documentation website (use the Help menu).
– tehhowch
Dec 31 '18 at 12:55
I have edited my code to include column = 11 and replaced k with column but still doesn't work. I don't understand why? @TheMaster I have already checked documentation before posting but don't know how to proceed.
– Jonathan Harker
Dec 31 '18 at 12:59
3
Only
getRange(string)
is available onSpreadsheet
(ss). So, you can usess.getRange('Sheet1!A1:B4')
.getRange(number,number)
is only available on sheet.ss.getActiveSheet().getRange(1,4)
– TheMaster
Dec 31 '18 at 13:42
1
Thanks @TheMaster I'm new at interacting here - I'll keep these points in mind for next time - have a great day.
– Jonathan Harker
Jan 1 at 13:06