I am trying to use an if formula in a data validation drop-down list in Google Sheets. It clearly shows that formulas are acceptable, but everytime I try, I get an error that says it's not a valid range. Is my syntax incorrect, or is this even possible?
Here is the code:
=if($I$1$="Hour(s)",code!$A$2:$A$24,code!$B$2:$B7)
Image of the problem
Related
I've created a script in GAS that extracts ID from a cluttered entry and then imputs it into a Formula that will look it up in the data sheet - however, the formulas created by the script cause the Google Sheet to throw out an error, as if the formula was faulty. However, using Google Sheets' "Find and Replace" window to replace a character for the same exact character (Like the starting = to =), it's possible to make it accept the formula and run it correctly - manually removing a character, pressing Enter and putting it back in also works.
I have tried implementing Find and Replace in GAS to make it automatic - and while the script works properly and replaces the given character, it doesn't do what the manual Find and Replace does - the formulas already corrected stay working, and the ones that are 'incorrect' are still erroneous.
for(var i = 0; i < range.getNumRows(); i++ ){
//Processing to extract the id
valsO[i][0]="=IF(ISERROR(VLOOKUP(\""+id+"*\";'Data'!B2:B$8400;1;FALSE));\"NONE\";VLOOKUP(\""+id+"*\";'Data'!B2:B$8400;1;FALSE))";
}
range=sheet.getRange(range.getRowIndex(), resultColumn, range.getNumRows());
range.setFormulas(valsO);
EDIT: Corrected from .setValues to .setFormulas and from IFERROR to ISERROR - however, the Formula Parse Error persists, despite working if it is typed in or copy-pasted in.
In the making of an anonymised version of the Spreadsheet for everyone to see and check, I accidentally stumbled into the right answer.
My issue was that I was expecting Google Sheets to parse the formulae generated from a script in a non-English language, just like it normally does when typed right into the sheet. Once I actually translated the entire Formula, including the Boolean value FALSE to English, the script started working properly.
Thank you for your help
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.
I am calling my google apps script function from my google spreadsheet from cell M1. The idea is to set values in many different rows in column L with the setValue call based on a set of custom rules. This spreadsheet is owned by me where I obviously have the edit rights. But I am getting the error "You do not have permission to call setValue". Why is that? Why am I not able to use the setValue to update my own spreadsheet? What is the purpose of setValue then if it cannot be used this way? How can I achieve what I am trying to do other than using setValue? Thanks.
From this documentation:
Custom functions return values, but they cannot set values outside the cells they are in. In most circumstances, a custom function in cell A1 cannot modify cell A5. However, if a custom function returns a double array, the results overflow the cell containing the function and fill the cells below and to the right of the cell containing the custom function. You can test this with a custom function containing return [[1,2],[3,4]];.
Maybe you are running the script as a custom function.
You can also check on these related threads:
https://stackoverflow.com/questions/35616991/custom-function-that-does-not-use-setvalue-is-returning-error-you-do-not-have-p
Google Script setValue permission
Can't use setValue(): results in a "You do not have permission to call setValue()" error
The answer really is to use custom menu. None of the past comments seem to mention how setValue can be used. The setValue is successfully used with custom menu but won't work with custom function.
Trying to make a spreadsheet on google sheets that scrapes data from a site.
I'm trying to get the sell price of items from rsbuddy exchange, eg:
https://rsbuddy.com/exchange/?id=1745
I have the code on google sheets as:
=IMPORTxml("https://rsbuddy.com/exchange/?id=1745","//*[#id='sell-price']")
But instead of showing me 1734gp it comes up as --- on the sheet.
I've tried adding /text() at the end of the query for the importxml but it doesn't change anything.
I'm guessing the solution is something similar?
I don't believe you can do it with xpath because it's populated dynamically. If you view the full source, you're getting what is there. It's literally ---
You can see the source data here which is in JSON and looks like it's tied to the page url id. Google sheets doesn't natively support json but this good person wrote a script and it seems to work well in my example sheet.
You'll need to do it via JSON, though you can't importJSON natively through Google Sheets. If you add this library as code to your sheet (via the script editor) then you can you can use =IMPORTJSON (with different parameters) to get the data back that you need.
http://blog.fastfedora.com/projects/import-json
I have a Google spreadsheet that contains charts which are properly displayed. When I am using a GAS to copy these charts to a Google document some of the charts are properly displayed in the document while others (which are displayed properly in the spreadsheet) are displaying the message "All series on a given axis must be of the same data type".
Since these are working charts I am not sure why I get this message. Is there a workaround to this problem or a known issue?
Any advise will help.
Thx!
Based on KRR answer. Even though the chart might be working in Google spreadsheet it appears that the getBlob of the chart rechecks the source values of the chart. You need to make sure that the source values (in my case above from a spreadsheet) all have the same data type.