I have two similar spreadsheets that share code in an apps script library.
I use named ranges to access the sheets from the code.
In one spreadsheet the ranges are sheetname!range like this:
and the other spreadsheet just uses range:
I have tried copying both spreadsheets and tried recreating ranges to match the other format but nothing seems to work. I have looked for something that tells me that the spreadsheets are different versions but cant find anything that is different. I can make the code look for either format but.....
If you copy a worksheet in a spreadsheet with a Named Range, then Google Sheets has to do something, as you can't have two Named Ranges with the same name in the same spreadsheet. What it does is create new Ranges with worksheet-level scope of the form: newworksheet!existingnamedrange. So I think that probably explains how you got to where you are.
In terms of fixing it? You can just delete the newworksheet!existingnamedrange name and recreate existingnamedrange. As you can have the same name in different spreadsheets. Or am I misunderstanding the problem?
Related
I have a Google Doc, within which I linked a Sheet. So, a table and/or a chart, that updates when the corresponding range in the linked spreadsheet updates.
Now, I want to make a copy of this document, so that the copy is linked to a (new) google sheet, which also is a copy of the original google sheet.
My first idea was using the Docs API to update some sort of reference, but it seems it's not possible to update an .. EmbeddedObject. I also tried using a Google Apps Script, but there I could also not figure out how to do this. I looked at a few more things, like creating a new doc using the Doc API, but I can't pass the inlineObjects or positionedObjects1, and apparently can't insert it afterwards either.
Did I just miss something? How can I make a duplicate of a Doc and a linked Sheet?
Any tricks, as hacky as they may seem, are very welcome!
1 While documents.create does accept both in the request body, the reference says "[...]any provided content, are ignored." (and indeed it is)
The Google Apps Script API for Docs has a number of methods defined that work with Named Ranges in Docs. While I am familiar with Named Ranges in Sheets, I cannot find a way to name a range in Docs.
Does anyone know how to name a range using the Docs UI? (obviously one can do so programmatically).
I was wondering about that also, but it looks as if it is not possible to edit or even see named ranges in the docs UI.
Lets hope, this will be changed in the future...
I am writing formulas to cells programmatically.
The following line of code:
formulaCells.setFormulaR1C1('=iferror(VLOOKUP(R[0]C[3],AutoCat!A:B,2,FALSE),"Requires Category")');
Adequately writes this formula into all the cells in the target Google Sheets file represented by formulaCells
=iferror(VLOOKUP(D2,AutoCat!A:B,2,FALSE),"Requires Category")
But the problem is that the formula defaults to the error flag "Requires Category" when it is written by Google Scripts, but if I write the very same formula manually into Google Sheets, the actual item identified by the VLOOKUP results.
This is so frustrating!
If I hover over the Google Script generated formula, the true solution from the VLOOKUP even appears in the flyover, but for some reason, does not appear in the cell.
Please help! Why will a Google Scripts generated formula not calculate properly wen the same formula entered manually will?
OK, after thinking I'd exhausted my mental resources on this, I tried one last thing, and it actually worked.
For some unknown reason, though the formula is accurate, Google Scripts generated formulas do not play well with a VLOOKUP which searches an unlimited range for a solution. So even though the VLOOKUP was finding the correct solution, it was not displaying it as the formula result.
I fixed this by creating in the Google Sheets file a named range of the data the VLOOKUP would search called AutoCategory, and then inserted that named range into the Google Scripts generated formula, and BOOM! the formula started working.
Here is the final code in Scripts:
formulaCells.setFormulaR1C1('=iferror(VLOOKUP(R[0]C[3],AutoCategory,2,FALSE),"Requires Category")');
And here is the final formula which is generated in Google Sheets:
=iferror(VLOOKUP(D2,AutoCategory,2,FALSE),"Requires Category")
setFormulaR1C1 requires R1C1 notation, which you provided with R[0]C[3], but AutoCat!A:B is A1 notation.
You could switch to setFormula() and pass in only A1 notation, but I think that using named ranges is a very good practice when combined with Google Apps Script.
In the end, I want to make a script that creates a folder that has other folders in it with a bunch of copies of a custom data sheet our school is using for data analysis.
As of now, I have created a whole system of Google Data Sheets that are connected through the IMPORTRANGE feature of Google sheets that our school uses to compare data. I would like to implement this system in other schools and wanted to try and write a Google App Script to set it up.
I have a couple of questions:
Is it possible to use a script to create a document is automatically set up to use the IMPORTRANGE feature to import data from another document?
If I have a sheet set up already (the standard data sheet we use) that I want to make 400 copies of in different folders, do I have to code the script to generate this document from scratch? Do I code it to pull a copy from somewhere? What do you guys think?
Does this even seem like something that's possible?
Thanks so much for your help guys!
Brandon
Sure. After you create the document, you'll just insert =IMPORTRANGE() using setFormula() or setFormulas(). You will have to manually grant permission for the sheet to import ranges the first time you open it, and any time after when you insert =IMPORTRANGE() with a reference to a new sheet, though.
This is no problem either. You can use the Drive Service and makeCopy() to copy a file into a destination folder you specify.
I want to create application which takes two different google forms data into the one spreadsheet and having two different sheets there on a single spreadsheet with the help of google apps script.
I've searched over a lot but hadn't find any satisfactory solution. Can anyone tell me that is that possible to acheive with google-apps-scripts?
Sorry, I don't have any piece of code this time.
It is impossible to insert data of two Google Forms directly to a single spreadsheet using GAS without involving another two spreadsheets, because now the Forms are able to deploy data only to own spreadsheet and GAS has no any service to access to the Forms.
There is a workaround which merges the Forms spreadsheets to a single spreadsheet using the ImportRange function (see bellow paragraph) but seems it is not suitable for you.
The spreadsheets have the ImportRange function which permits to import a source spreadsheet range to a destination spreadsheet, for instance, there is a task to import spreadsheet_1 columns A, B, C of Sheet1 and spreadsheet_2 columns B, C of the Sheet2 to spreadsheet_0 columns F, G, H, I and J. To achieve it is necessary to place to the spreadsheet_0 cell F1 the =ImportRange("spreadsheet_1_key", "Sheet1!A:C") formula and the cell I1 should contain the =ImportRange("spreadsheet_2_key", "Sheet2!B:C") formula.
For anyone who ends up at this question, looking for some general knowledge, you can change the form destination. In the form editor, choose RESPONSES, CHANGE RESPONSE DESTINATION. The form responses can be sent to another spreadsheet. I'm not sure if this is a capability that didn't exist when this question was first asked, but for anyone doing a general search, you might end up here.