assigning to an array in google scriptCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
Complex numbers z=-3-4i polar form
How to keep bees out of canned beverages?
Nails holding drywall
Older movie/show about humans on derelict alien warship which refuels by passing through a star
How do I check if a string is entirely made of the same substring?
Drawing a german abacus as in the books of Adam Ries
Is Electric Central Heating worth it if using Solar Panels?
Why do real positive eigenvalues result in an unstable system? What about eigenvalues between 0 and 1? or 1?
What is purpose of DB Browser(dbbrowser.aspx) under admin tool?
What is the most expensive material in the world that could be used to create Pun-Pun's lute?
"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?
How to have a sharp product image?
Is there a word for the censored part of a video?
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
Double-nominative constructions and “von”
NPN: Not fully sinking to GND
Will I lose my paid in full property
Extracting Dirichlet series coefficients
What is the term for a person whose job is to place products on shelves in stores?
How much of a wave function must reside inside event horizon for it to be consumed by the black hole?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
Is there metaphorical meaning of "aus der Haft entlassen"?
Why do distances seem to matter in the Foundation world?
Was Dennis Ritchie being too modest in this quote about C and Pascal?
assigning to an array in google script
Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?PHP: Delete an element from an arrayHow to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This is probably an ignorant mistake on my part, but I am trying to assign different values from different column to an array to put in a master sheet. I would like the last column to be equal the the sheet name where the data came from to track it back.
I feel I am close, but when I get to the last column which I want to be the sheet name I get the following error: Cannot convert Array to Object[][]. (line 19, file "combineTOmaster")
This is my code so far. I know the issue is the other column are array[[][]] and the last one is array [][] but I don't know how to fix it. Any ideas?
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (colIndex = "orginalsheet")
var colValues = [];
var array = [];
for (var i = 0; i < numRows-1;i++)
array[i] = sheetName;
colValues = array;
else
var colValues = [];
Logger.log(colValues);
return colValues;
Thank you
arrays google-apps-script
add a comment |
This is probably an ignorant mistake on my part, but I am trying to assign different values from different column to an array to put in a master sheet. I would like the last column to be equal the the sheet name where the data came from to track it back.
I feel I am close, but when I get to the last column which I want to be the sheet name I get the following error: Cannot convert Array to Object[][]. (line 19, file "combineTOmaster")
This is my code so far. I know the issue is the other column are array[[][]] and the last one is array [][] but I don't know how to fix it. Any ideas?
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (colIndex = "orginalsheet")
var colValues = [];
var array = [];
for (var i = 0; i < numRows-1;i++)
array[i] = sheetName;
colValues = array;
else
var colValues = [];
Logger.log(colValues);
return colValues;
Thank you
arrays google-apps-script
Should it really beorgin
? Probably you meantorigin
, i.e."originalsheet"
. Then there's the issue that you use=
as the operator in a conditional check. You must review language fundamentals: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…
– tehhowch
Mar 9 at 14:38
@tehhoch Yes rookie mistake with the = versus ==. That page is a great resource.
– Jerome Learman
Mar 10 at 11:51
add a comment |
This is probably an ignorant mistake on my part, but I am trying to assign different values from different column to an array to put in a master sheet. I would like the last column to be equal the the sheet name where the data came from to track it back.
I feel I am close, but when I get to the last column which I want to be the sheet name I get the following error: Cannot convert Array to Object[][]. (line 19, file "combineTOmaster")
This is my code so far. I know the issue is the other column are array[[][]] and the last one is array [][] but I don't know how to fix it. Any ideas?
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (colIndex = "orginalsheet")
var colValues = [];
var array = [];
for (var i = 0; i < numRows-1;i++)
array[i] = sheetName;
colValues = array;
else
var colValues = [];
Logger.log(colValues);
return colValues;
Thank you
arrays google-apps-script
This is probably an ignorant mistake on my part, but I am trying to assign different values from different column to an array to put in a master sheet. I would like the last column to be equal the the sheet name where the data came from to track it back.
I feel I am close, but when I get to the last column which I want to be the sheet name I get the following error: Cannot convert Array to Object[][]. (line 19, file "combineTOmaster")
This is my code so far. I know the issue is the other column are array[[][]] and the last one is array [][] but I don't know how to fix it. Any ideas?
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (colIndex = "orginalsheet")
var colValues = [];
var array = [];
for (var i = 0; i < numRows-1;i++)
array[i] = sheetName;
colValues = array;
else
var colValues = [];
Logger.log(colValues);
return colValues;
Thank you
arrays google-apps-script
arrays google-apps-script
asked Mar 9 at 7:31
Jerome LearmanJerome Learman
115
115
Should it really beorgin
? Probably you meantorigin
, i.e."originalsheet"
. Then there's the issue that you use=
as the operator in a conditional check. You must review language fundamentals: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…
– tehhowch
Mar 9 at 14:38
@tehhoch Yes rookie mistake with the = versus ==. That page is a great resource.
– Jerome Learman
Mar 10 at 11:51
add a comment |
Should it really beorgin
? Probably you meantorigin
, i.e."originalsheet"
. Then there's the issue that you use=
as the operator in a conditional check. You must review language fundamentals: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…
– tehhowch
Mar 9 at 14:38
@tehhoch Yes rookie mistake with the = versus ==. That page is a great resource.
– Jerome Learman
Mar 10 at 11:51
Should it really be
orgin
? Probably you meant origin
, i.e. "originalsheet"
. Then there's the issue that you use =
as the operator in a conditional check. You must review language fundamentals: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…– tehhowch
Mar 9 at 14:38
Should it really be
orgin
? Probably you meant origin
, i.e. "originalsheet"
. Then there's the issue that you use =
as the operator in a conditional check. You must review language fundamentals: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…– tehhowch
Mar 9 at 14:38
@tehhoch Yes rookie mistake with the = versus ==. That page is a great resource.
– Jerome Learman
Mar 10 at 11:51
@tehhoch Yes rookie mistake with the = versus ==. That page is a great resource.
– Jerome Learman
Mar 10 at 11:51
add a comment |
2 Answers
2
active
oldest
votes
Lets break your function down -
// you're passing column header and sheet name, OK
function getColValues(label, sheetName)
// getting sheet, OK
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// getting column index, OK
var colIndex = getColumnIndex(label, sheetName);
// getting number of rows to collect, OK
var numRows = ss.getLastRow() - 1;
// at this point, i assume, variable colIndex is a number, because it should be
// if label column exists, colIndex will be greater than 0, OK
if (colIndex > 0)
// get values of that column, OK
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
// colValues will be like this, at this point-
// [ [value], [value], [value] ... ]
else if ((colIndex = 'orginalsheet'))
// NOT OK, = sign assigns 'orginalsheet' to colIndex
// do you wanna assign or compare?
// to compare, use == sign
// besides why are you assigning a string value to colIndex ?
// colIndex should be a number, in my understanding
// now, what do you wanna do here ?
var colValues = [];
var array = [];
for (var i = 0; i < numRows - 1; i++)
array[i] = sheetName;
colValues = array;
// at his point, colValues is -
// [sheetName, sheetName, sheetName...]
// is this correct colValues ?
// i guess not
// i think you're trying to use sheetName as a column value for every row
// if that is the case, do this
var colValues = [];
for (var i = 0; i < numRows; i++) colValues.push([sheetName]);
// now colValues is -
// [ [sheetName], [sheetName], [sheetName].... ]
// which you can insert in a sheet as values of a column
else
var colValues = [];
Logger.log(colValues);
return colValues;
add a comment |
@ra89fi Thank you so much. You lead me to the answer. So mess up 1 was using = and not ==. Mess up two was using colIndex instead of label. Mess up three was not using push. Is there a good resource on push? Thank you again!!
Below is the final code that worked for me.
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (label == "orginalsheet")
var colValues = [];
for (var i = 0; i < numRows;i++)
colValues.push([sheetName]);
else
var colValues = [];
return colValues;
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%2f55075071%2fassigning-to-an-array-in-google-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Lets break your function down -
// you're passing column header and sheet name, OK
function getColValues(label, sheetName)
// getting sheet, OK
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// getting column index, OK
var colIndex = getColumnIndex(label, sheetName);
// getting number of rows to collect, OK
var numRows = ss.getLastRow() - 1;
// at this point, i assume, variable colIndex is a number, because it should be
// if label column exists, colIndex will be greater than 0, OK
if (colIndex > 0)
// get values of that column, OK
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
// colValues will be like this, at this point-
// [ [value], [value], [value] ... ]
else if ((colIndex = 'orginalsheet'))
// NOT OK, = sign assigns 'orginalsheet' to colIndex
// do you wanna assign or compare?
// to compare, use == sign
// besides why are you assigning a string value to colIndex ?
// colIndex should be a number, in my understanding
// now, what do you wanna do here ?
var colValues = [];
var array = [];
for (var i = 0; i < numRows - 1; i++)
array[i] = sheetName;
colValues = array;
// at his point, colValues is -
// [sheetName, sheetName, sheetName...]
// is this correct colValues ?
// i guess not
// i think you're trying to use sheetName as a column value for every row
// if that is the case, do this
var colValues = [];
for (var i = 0; i < numRows; i++) colValues.push([sheetName]);
// now colValues is -
// [ [sheetName], [sheetName], [sheetName].... ]
// which you can insert in a sheet as values of a column
else
var colValues = [];
Logger.log(colValues);
return colValues;
add a comment |
Lets break your function down -
// you're passing column header and sheet name, OK
function getColValues(label, sheetName)
// getting sheet, OK
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// getting column index, OK
var colIndex = getColumnIndex(label, sheetName);
// getting number of rows to collect, OK
var numRows = ss.getLastRow() - 1;
// at this point, i assume, variable colIndex is a number, because it should be
// if label column exists, colIndex will be greater than 0, OK
if (colIndex > 0)
// get values of that column, OK
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
// colValues will be like this, at this point-
// [ [value], [value], [value] ... ]
else if ((colIndex = 'orginalsheet'))
// NOT OK, = sign assigns 'orginalsheet' to colIndex
// do you wanna assign or compare?
// to compare, use == sign
// besides why are you assigning a string value to colIndex ?
// colIndex should be a number, in my understanding
// now, what do you wanna do here ?
var colValues = [];
var array = [];
for (var i = 0; i < numRows - 1; i++)
array[i] = sheetName;
colValues = array;
// at his point, colValues is -
// [sheetName, sheetName, sheetName...]
// is this correct colValues ?
// i guess not
// i think you're trying to use sheetName as a column value for every row
// if that is the case, do this
var colValues = [];
for (var i = 0; i < numRows; i++) colValues.push([sheetName]);
// now colValues is -
// [ [sheetName], [sheetName], [sheetName].... ]
// which you can insert in a sheet as values of a column
else
var colValues = [];
Logger.log(colValues);
return colValues;
add a comment |
Lets break your function down -
// you're passing column header and sheet name, OK
function getColValues(label, sheetName)
// getting sheet, OK
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// getting column index, OK
var colIndex = getColumnIndex(label, sheetName);
// getting number of rows to collect, OK
var numRows = ss.getLastRow() - 1;
// at this point, i assume, variable colIndex is a number, because it should be
// if label column exists, colIndex will be greater than 0, OK
if (colIndex > 0)
// get values of that column, OK
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
// colValues will be like this, at this point-
// [ [value], [value], [value] ... ]
else if ((colIndex = 'orginalsheet'))
// NOT OK, = sign assigns 'orginalsheet' to colIndex
// do you wanna assign or compare?
// to compare, use == sign
// besides why are you assigning a string value to colIndex ?
// colIndex should be a number, in my understanding
// now, what do you wanna do here ?
var colValues = [];
var array = [];
for (var i = 0; i < numRows - 1; i++)
array[i] = sheetName;
colValues = array;
// at his point, colValues is -
// [sheetName, sheetName, sheetName...]
// is this correct colValues ?
// i guess not
// i think you're trying to use sheetName as a column value for every row
// if that is the case, do this
var colValues = [];
for (var i = 0; i < numRows; i++) colValues.push([sheetName]);
// now colValues is -
// [ [sheetName], [sheetName], [sheetName].... ]
// which you can insert in a sheet as values of a column
else
var colValues = [];
Logger.log(colValues);
return colValues;
Lets break your function down -
// you're passing column header and sheet name, OK
function getColValues(label, sheetName)
// getting sheet, OK
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
// getting column index, OK
var colIndex = getColumnIndex(label, sheetName);
// getting number of rows to collect, OK
var numRows = ss.getLastRow() - 1;
// at this point, i assume, variable colIndex is a number, because it should be
// if label column exists, colIndex will be greater than 0, OK
if (colIndex > 0)
// get values of that column, OK
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
// colValues will be like this, at this point-
// [ [value], [value], [value] ... ]
else if ((colIndex = 'orginalsheet'))
// NOT OK, = sign assigns 'orginalsheet' to colIndex
// do you wanna assign or compare?
// to compare, use == sign
// besides why are you assigning a string value to colIndex ?
// colIndex should be a number, in my understanding
// now, what do you wanna do here ?
var colValues = [];
var array = [];
for (var i = 0; i < numRows - 1; i++)
array[i] = sheetName;
colValues = array;
// at his point, colValues is -
// [sheetName, sheetName, sheetName...]
// is this correct colValues ?
// i guess not
// i think you're trying to use sheetName as a column value for every row
// if that is the case, do this
var colValues = [];
for (var i = 0; i < numRows; i++) colValues.push([sheetName]);
// now colValues is -
// [ [sheetName], [sheetName], [sheetName].... ]
// which you can insert in a sheet as values of a column
else
var colValues = [];
Logger.log(colValues);
return colValues;
answered Mar 9 at 9:15
ra89fira89fi
969168
969168
add a comment |
add a comment |
@ra89fi Thank you so much. You lead me to the answer. So mess up 1 was using = and not ==. Mess up two was using colIndex instead of label. Mess up three was not using push. Is there a good resource on push? Thank you again!!
Below is the final code that worked for me.
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (label == "orginalsheet")
var colValues = [];
for (var i = 0; i < numRows;i++)
colValues.push([sheetName]);
else
var colValues = [];
return colValues;
add a comment |
@ra89fi Thank you so much. You lead me to the answer. So mess up 1 was using = and not ==. Mess up two was using colIndex instead of label. Mess up three was not using push. Is there a good resource on push? Thank you again!!
Below is the final code that worked for me.
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (label == "orginalsheet")
var colValues = [];
for (var i = 0; i < numRows;i++)
colValues.push([sheetName]);
else
var colValues = [];
return colValues;
add a comment |
@ra89fi Thank you so much. You lead me to the answer. So mess up 1 was using = and not ==. Mess up two was using colIndex instead of label. Mess up three was not using push. Is there a good resource on push? Thank you again!!
Below is the final code that worked for me.
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (label == "orginalsheet")
var colValues = [];
for (var i = 0; i < numRows;i++)
colValues.push([sheetName]);
else
var colValues = [];
return colValues;
@ra89fi Thank you so much. You lead me to the answer. So mess up 1 was using = and not ==. Mess up two was using colIndex instead of label. Mess up three was not using push. Is there a good resource on push? Thank you again!!
Below is the final code that worked for me.
function getColValues(label,sheetName)
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
var colIndex = getColumnIndex(label, sheetName);
var numRows = ss.getLastRow() -1;
if (colIndex > 0 )
var colValues = ss.getRange(2, colIndex, numRows, 1).getValues();
else if (label == "orginalsheet")
var colValues = [];
for (var i = 0; i < numRows;i++)
colValues.push([sheetName]);
else
var colValues = [];
return colValues;
answered Mar 10 at 12:02
Jerome LearmanJerome Learman
115
115
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%2f55075071%2fassigning-to-an-array-in-google-script%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
Should it really be
orgin
? Probably you meantorigin
, i.e."originalsheet"
. Then there's the issue that you use=
as the operator in a conditional check. You must review language fundamentals: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…– tehhowch
Mar 9 at 14:38
@tehhoch Yes rookie mistake with the = versus ==. That page is a great resource.
– Jerome Learman
Mar 10 at 11:51