Get list of values from multiple tabs and copy to a column in another sheet?

pdrops

I've created a script from searches on stackoverflow and come up with this so far:

function collectData(){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheets = ss.getSheets();
var target = ss.getSheetByName("Export");

for ( i = 0; i < sheets.length; i++){  
var names = sheets[i].getRange("B1").getValue();    

Logger.log(names);

 }
}

This is working as expected but I am trying to then list the values in another sheet. I've tried copyTo and setValues and push to send the list of values to a specific sheet but keep getting errors.

user3717023

To set values in some range of a spreadsheet, you need to arrange them in a double array. A row is [[x, y, z]], a column is [[x], [y], [z]]. Since you want a column, the logic would be

var names = [];
for (var i = 0; i < sheets.length; i++){  
  names.push([sheets[i].getRange("B1").getValue()]); 
}
target.getRange(1, 1, names.length, 1).setValues(names);

Reference: getRange.

To make a row instead, some square brackets get moved around:

var names = [];
for (var i = 0; i < sheets.length; i++){  
  names.push(sheets[i].getRange("B1").getValue()); 
}
target.getRange(1, 1, 1, names.length).setValues([names]);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Copy conditional values from one column to another

create multiple columns from list of values of another column

Copy row values to another sheet

Copy and paste as values to another sheet

Copy values only from one sheet to another

Copy and paste cell values (not formulae) from one sheet to another

How to copy values based on multiple cell criteria to another Sheet

Split a Google Sheet into multiple tabs based on column values

Copy multiple values from from a single column

Copy values from one dataframe column to another

How to copy values from table for another column

Sum multiple values from another sheet

excel vba: copy rows if data match with values in column in another sheet

Input values in a column according to the reference from another column of the same sheet

Copy values from one sheet to another without including pictures

Map/Copy values from one sheet to another in excel if they match on column header

How to copy cell values from multiple (but not all) rows and columns from one sheet to another sheet

Copy a value from one sheet to another and then copy result back to same sheet in different column

VBA, Copy values from one sheet to another using header names

In excel is it possible to create a list of unique values from a column and copy data from another column with it?

VBA - How to copy values from sheets to another sheet

filter column from a list on another sheet

How to get unique values from a specific column from multiple sheets in a separate sheet using Excel or Google sheets?

To copy Cell values from a range and paste it in a single row of another sheet

Script to copy values only from multiple tabs to another spreadsheet

Copy / paste background color from one column to another sheet in a column with matched values

Excel VBA - Copy data from sheet with Column values as Subheaders

Copy column data from one sheet to another sheet if values in key column matches

Google Script - Copy values from column to another sheet matching adjacent cell