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,
Related
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();
};
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);
}
}
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');
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"))
}
When I try to append a list which contain list of image which I parsed from JSON into an array in Swift iOS I mm getting an error:
"Cannot invoke append with an argument list of type json"
I'm totally new to iOS (Swift).
This is the basic code I'm using Alamofire, SwiftyJSON and SwiftyUserDefaults.
import Alamofire
import SwiftyJSON
import SwiftyUserDefaults
var NameArr: [String] = []
var ProfileImgArr: [String] = []
var StyleTypeArr: [String] = []
var ImageStackArr = [String]()
var SingleImageArr: [String] = []
var ItemNameArr: [String] = []
var TagsArr: [String] = []
var ImageArrSet: [String] = []
var LikeCountArr: [Int] = []
var ImageFlag: [String] = []
var testCount: (Int) = 0
var imageCounter = 0
var normalCounter = 0
var normalCounter1 = 0
var normalCounter2 = 0
// JSON load
let url = "http://zapmob.cloudapp.net/media/"
func JsonLoad() {
Alamofire.request(.GET, "http://zapmob.cloudapp.net/feed/?format=json")
.responseJSON { (request, response, data, error) in
println(error)
println(response)
let json = JSON(data!)
for (var j = 0; j <= json.count-1; j++) {
let FullName = json[j]["user_details_dict"]["username"].string
self.NameArr.append(FullName!)
let ProfilePic = json[j]["user_details_dict"]["profile_pic"].string
self.ProfileImgArr.append(ProfilePic!)
let StyleType = json[j]["fashion_type"].string
self.StyleTypeArr.append(StyleType!)
// -- Start of error part --v
var ImageStackArrs = [json[j]["images"].array!]
println(ImageStackArrs)
Defaults["ImageArrStack"] = ImageStackArrs
for (var x = 0; x <= ImageStackArrs.count - 1; x++) {
Defaults["ImageStackCache"] = [ImageStackArrs[x][0]]
}
// -- End of error part --^
let ItemName = json[j]["album_title"].string
self.ItemNameArr.append(ItemName!)
let LikeCount = json[j]["like"].count
self.LikeCountArr.append(LikeCount)
}
Defaults["NameCache"] = self.NameArr
Defaults["ProfileImgCache"] = self.ProfileImgArr
Defaults["StyleTypeCache"] = self.StyleTypeArr
Defaults["ItemNameCache"] = self.ItemNameArr
Defaults["TagsCache"] = self.TagsArr
Defaults["LikeCountCache"] = self.LikeCountArr
}
}
Without going through the code in detail: This error is normally called when trying to append to an optional array.