0
votes

I have this one main file in Google Sheets. Now, I need to split this data such that its gets sent to " X " number of new files ( not a separate sheet). The data that is being sent is a subset of the data from the main file. Is it possible to create these new workbooks and populate them with this subset data?

I tried creating new sheets, but the script is only working on creating it within the currently active sheet, and I cant find anything that is copying a range to a new sheet.

1
Please explain if the document is static (just copy data to separate files) or dynamic (the separate files should update its data when the original document changes), and please change your question to reflect the same. In the dynamic case, you might want to see query - daniel
The document that i split up is static, but i want these sub-sheets to return data else where dynamically. i guess i will work on query and let you guys know - Anmol Kular

1 Answers

3
votes

so i did figure out how to work around this thing.

now i didnt want to create a copy of the file. i wanted it to work somewhat like importrange.

var target2 = SpreadsheetApp.openById("Sheet url");              
var target_sheet2 = target2.getSheetByName("Sheet1");
var source_rangefor2 = source_sheet.getRange("A7:C11");                                              
var target_rangefor2 = target_sheet2.getRange("A1:C5");                                             
var values = source_rangefor2.getValues();
target_rangefor2.setValues(values);

this copies the said range from the main sheet to the given range in the target sheet.

Hope this helps other people.