The resulting array was too large in Google Sheets - google-sheets

I'm using the following formula, and I'm getting: The resulting array was too large.
Any ideas? I have over 20k rows.
UPDATE: If I can accomplish this formula with a script, that would be great. Thanks!
=UNIQUE(ARRAYFORMULA({IMPORTRANGE(Links!B2,"uno!A:AF");IMPORTRANGE(Links!B3,"dos!A:AF");IMPORTRANGE(Links!B4,"tres!A:AF");IMPORTRANGE(Links!B5,"cuatro!A:AF");IMPORTRANGE(Links!B6,"cinco!A:AF")}))

Try by script this way
function test() {
var dest = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
var ss = SpreadsheetApp.openById('id2')
var sh = ss.getSheetByName('uno')
var values = sh.getRange('A1:AF'+sh.getLastRow()).getValues()
dest.getRange(dest.getLastRow()+1,1,values.length,values[0].length).setValues(values)
SpreadsheetApp.flush();
var ss = SpreadsheetApp.openById('id2')
var sh = ss.getSheetByName('dos')
var values = sh.getRange('A1:AF'+sh.getLastRow()).getValues()
dest.getRange(dest.getLastRow()+1,1,values.length,values[0].length).setValues(values)
SpreadsheetApp.flush();
var ss = SpreadsheetApp.openById('id3')
var sh = ss.getSheetByName('tres')
var values = sh.getRange('A1:AF'+sh.getLastRow()).getValues()
dest.getRange(dest.getLastRow()+1,1,values.length,values[0].length).setValues(values)
SpreadsheetApp.flush();
var ss = SpreadsheetApp.openById('id4')
var sh = ss.getSheetByName('cuatro')
var values = sh.getRange('A1:AF'+sh.getLastRow()).getValues()
dest.getRange(dest.getLastRow()+1,1,values.length,values[0].length).setValues(values)
SpreadsheetApp.flush();
var ss = SpreadsheetApp.openById('id5')
var sh = ss.getSheetByName('cinco')
var values = sh.getRange('A1:AF'+sh.getLastRow()).getValues()
dest.getRange(dest.getLastRow()+1,1,values.length,values[0].length).setValues(values)
SpreadsheetApp.flush();
};

Related

Formating Copied to new Sheet Google Scripts (Google Sheets)

Trying to get the formatting copied over from the front sheet, but it takes the forumla which is a import range, is there any way to achieve this without showing the ref error.
function BrandSheets() {
var ss = SpreadsheetApp.getActive();
var Frontsheet = ss.getSheets()[0];
var Header_range = Frontsheet.getRange(1,1,1,13);
var CurrentBrand = Frontsheet.getRange(2,3).getValue();
var CurrentTopBrand = 2;
var CurrentBottomBrand = 2;
var CheckBrand = CurrentBrand;
Frontsheet.getRange(1,3).activate();
Frontsheet.getCurrentCell().getNextDataCell(SpreadsheetApp.Direction.DOWN).activate();
var FLastCell = Frontsheet.getActiveCell();
var FLastRow = FLastCell.getRow();
for(var i = 2;i<=FLastRow+1;i++){
var CheckBrand = Frontsheet.getRange(i,3).getValue();
if (CheckBrand == CurrentBrand){
var CurrentBottomBrand = i
}
else{
var CurrentBottomBrand = i
var BrandTable = Frontsheet.getRange(CurrentTopBrand,1,CurrentBottomBrand-CurrentTopBrand,13);
var NewSheet = SpreadsheetApp.getActiveSpreadsheet().insertSheet(CurrentBrand);
var NewHeader_range = NewSheet.getRange(1,1,1,13);
var NewBrandTable = NewSheet.getRange(2,1,CurrentBottomBrand-CurrentTopBrand,13);
Header_range.copyTo(NewHeader_range,{contentsOnly:true});
BrandTable.copyTo(NewBrandTable);
var CurrentTopBrand = i;
var CurrentBrand = Frontsheet.getRange(i,3).getValue();
SpreadsheetApp.getActiveSpreadsheet().getSheets().forEach( sheet => sheet.setTabColor("grey"));
}
}
}
I tried Header_range.copyTo(NewHeader_range,{contentsOnly:true,formatOnly:true});
But this is where the bug of ref comes up. Issue Ref
Many thanks,

Automatic copy a row when a certain value is given

I need to automatically copy a row when a certain value is given.
With Moveto it works, but with copyto it does not.
Can someone help me? tx
function myFunction3() {
var sheetNameToWatch = "Planning";
var columnNumberToWatch = 12;
var valueToWatch = "Running";
var sheetNameCopyTheRowTo = "Facturatie";
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();
var rangeToCopy = sheet.getActiveCell();
if (sheet.getName() == sheetNameToWatch
&& range.getColumn() == columnNumberToWatch
&& range.getValue() == valueToWatch)
{
var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
sheet.getRange(range.getRow(),1,1,sheet.getLastColumn()).copyTo(targetRange);
}
}

Google Sheets Auto Time Stamp

My script quit working for google sheets. I can't see why line 7 is hanging up.
Here is the script
function onEdit(event)
{
var timezone = "GMT-7";
var timestamp_format = "MM-dd-yyyy HH:mm:ss";
var updateColName = "Narrative";
var timeStampColName = "Time Stamp";
var sheet = event.source.getSheetByName('Narrative');
var actRng = event.source.getActiveRange();
var editColumn = actRng.getColumn();
var index = actRng.getRowIndex();
var headers = sheet.getRange(2, 2, 2, sheet.getLastColumn()).getValues();
var dateCol = headers[0].indexOf(timeStampColName);
var updateCol = headers[0].indexOf(updateColName); updateCol = updateCol+1;
if (dateCol > -1 && index > 1 && editColumn == updateCol) {
var cell = sheet.getRange(index, dateCol + 1);
var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
cell.setValue(date);
}
}
Any help would be appreciated!
Has the name of the sheet changed?
var sheet = event.source.getSheetByName('Narrative');

SWIFT : Basic Loops and Arrays

Can I put this in a loop instead of having to manually code it in for each chapter?
var chp1 = Array(Chapters[0].componentsSeparatedByString("\n"))
var chp2 = Array(Chapters[1].componentsSeparatedByString("\n"))
var chp3 = Array(Chapters[2].componentsSeparatedByString("\n"))
var chp4 = Array(Chapters[3].componentsSeparatedByString("\n"))
var chp5 = Array(Chapters[4].componentsSeparatedByString("\n"))
var chp6 = Array(Chapters[5].componentsSeparatedByString("\n"))
var chp7 = Array(Chapters[6].componentsSeparatedByString("\n"))
var chp8 = Array(Chapters[7].componentsSeparatedByString("\n"))
Yes you can use
var chp = []
for chapter in Chapters
{
chp.append(chapter.componentsSeparatedByString("\n")))
}
now you can access to the chapters like
chp[0]
chp[1]
chp[2]
Also you don't need to cast return value to Array.
for range in 0...8 {
var chp = Chapters[range]
let result = chp.componentsSeparatedByString("\n"))
}
Or
for (_, chapter) in Chapters.enumerate() {
let result = chapter.componentsSeparatedByString("\n"))
}

Function that returns an Array from an Array of Arrays

Im trying to make a function that takes in an Array of Arrays that returns a single Array so that all values ("names") have there own index.
var namesList1 = [String]()
var namesList2 = [String]()
var namesList3 = [String]()
namesList1 = ["Paul","John","Ringo","George"]
namesList2 = ["Julie","Sarah","Jackie"]
namesList3 = ["Jim","Jack","Charlie","Sally","Debra"]
var namesCombinedArray = [NSArray]()
namesCombinedArray = [namesList1,namesList2,namesList3]
func total(arrays:NSArray) -> NSArray{
// how to loop to create an array with index(s) to all names ??
var completeList = [NSArray]()
return completeList
}
You could use flatMap:
let namesList1 = ["Paul","John","Ringo","George"]
let namesList2 = ["Julie","Sarah","Jackie"]
let namesList3 = ["Jim","Jack","Charlie","Sally","Debra"]
let namesCombinedArray = [namesList1,namesList2,namesList3]
let completeList = namesCombinedArray.flatMap{$0}
print(completeList)
// [Paul, John, Ringo, George, Julie, Sarah, Jackie, Jim, Jack, Charlie, Sally, Debra]

Resources