How to display #REF! (You need to connect these sheets) when using IFERROR to display Blank Cell - google-sheets

I understand that Google Sheets must be explicitly granted permission to pull data from other spreadsheets using IMPORTRANGE
However, when using IFERROR alongside VLOOKUP to display the value argument has a blank cell - How do you still allow for the #REF! (You need to connect these sheets) to be displayed?
I appreciate that as a workaround I could just display a "." but I'm curious if it's possible to legitimately without a workaround display a blank cell with no valid result but still allow for #REF! (You need to connect these sheets) to be displayed?
=IFERROR(VLOOKUP(Meta!$A$12,IMPORTRANGE(""&$M31&"","Template!$A$1:$H$6"),7, false), "")

yes, they need to be connected and IFERROR will only hide that #REF! error. if you got complex (non-standalone IMPORTRANGE formula) that Allow access button will not appear. you are always obligated to run the IMPORTRANGE fx as standalone to establish the connection (it can be just a single cell - =IMPORTRANGE(""&$M31&"","Template!$A$1")) and only then use your complex (multi-layer) formula.

This would decrease performance, probably by a lot, but I think this (or something similar) would technically work:
=if(1+0*importrange(...),iferror(vlookup(...)))

Related

Google sheets, vlookup, iferror formula in a script as a function

I have the below formula that populates data from another sheet into one of the columns.
The problem is that I have to allow access between the sheets for the below to work. Unfortunately with the IFERROR statement I don't see the "Allow access to the sheet" popup.
So i have to remove IFERROR and re-add it manually each time.
Is there a way to use vlookup without IFERROR?
Or could I put this formula as a function using the script ?
=ARRAYFORMULA(LOWER(IFERROR(IF(C1:C="test",VLOOKUP(A1:A,IMPORTRANGE("sheet_id","Master !L:N"),3,false),hosts!L3:L))))
many thanks
That is NOT the problem with your formula. (actually it seems to work just fine)
The way the IMPORTRANGE function works is that you only have to "Allow access ONCE.
Once access is granted you don't have to do it again. The two sheets are connected for eternity :)
Tip:
Instead of trying to grand access from inside your formula, try the following
On another cell (any empty cell will do) use just the IMPORTRANGE formula:
=IMPORTRANGE("sheet_id","Master !L:N")
You will be asked to give access. Allow it.
Now the sheets are connected and your formula works as expected.

In Google Sheets, how do I filter based on the value of another cell?

This might seem like a simple question, but I'm really struggling to get it to work. Google Sheets has 'filter by condition', so I'm hoping I can enter the condition of a cell value in order to filter on rows with only that value.
So for example, in a column called Manager, I would like to filter by condition from another tab on cell =Sheet1!A2, where this is the manager name. However, it's only pulling through rows where the cell is blank.
Does anyone know how this could work, or even if it's meant to work the way I would like?
if this is filter view not FILTER formula then you need to use INDIRECT because you refer to value on another sheet. try:
=INDIRECT("Sheet1!A2")

ARRAYFORMULA with IMPORTRANGE

In column B are listed IDs of Google Sheets. In column C are listed cells, from which I want to import data.
Screenshot of the table
In column D is shown the result of using IMPORTRANGE() by simply dragging it. e.g. for D1 it looks like:
=IMPORTRANGE(B1;C1)
for D2:
=IMPORTRANGE(B2;C2)
and so on.
In column E I want to display the same result but using ARRAYFORMULA that looks like:
=ARRAYFORMULA(IMPORTRANGE(B2:B4,C2:C4))
but the function displays only the data from the first spreadsheet.
People complain about this permissions issue a lot, but it's not hard to solve. What I do is have a sheet which I name "Splash sheet" into which I paste the URLs of the documents I wish to link. To its right is a column headed "permit to connect" which contains IMPORTRANGE formulas importing a single cell from each sheet -- usually a cell containing a confirmation code, number or document name -- on a sheet also named "Splash Sheet." For example,
=IF(B3="enter URL",,CONCATENATE(IMPORTRANGE(B3,"Splash sheet!A1")," ",IMPORTRANGE(B3,"Splash sheet!B1")))
So, when you first connect a spreadsheet via its URL, you get those messages telling you you need to connect, you click the Permit Access, the confirmation code/number/document name appears in the second column, and voilá, your sheets are connected forevermore! Now all your other IMPORTRANGEs referencing that URL will work, and you can use IMPORTRANGE formulas that reference the URL-containing cells on the "splash sheet."
As for the OP's original question, I came here seeking an answer to the same problem, and after more research have realized that we are attempting the impossible here. No way to do this an ARRAYFORMULA. No way around writing formulas that reference every single cell a document's URL may go into.
Problem is you can't make arrays of arrays in spreadsheets; that would involve multiple dimensions, and the medium is inherently two-dimensional. This is what people use databases for.
ARRAYFORMULA doesn't work when importing data (I think it relates to permissions). You could use something like this, =IFERROR(IMPORTRANGE(B5:B7;C5:C7)) and pre-fill the column first, but still there would be the permissions issue. Each new imported sheet needs it's permissions granted by a user.
TLDR: If I understand your intention correctly when you say you would like to see
=ARRAYFORMULA(IMPORTRANGE(B2:B4,C2:C4)), I believe you can make that
happen using the following.
=ARRAYFORMULA(IMPORTRANGE(
INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)),
INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4))
)
Breakdown
Use IMPORTRANGE with INDIRECT to create ranges inside ARRAYFORMULA
Call INDIRECT with the ADDRESS function
Call ADDRESS with the ROW and COLUMN functions since they take ranges via ARRAYFORMULA
using IMPORTRANGE with INDIRECT
IMPORTRANGE's two parameters are the spreadsheet url stored in B2:B4 for this example and the range (e.g. sheet!A1:B2) stored in C2:C4.
Since IMPORTRANGE doesn't take a range reference directly as you mentioned, you'll need to build it for each row with ARRAYFORMULA using the INDIRECT function.
INDIRECT can be used to compose a cell reference using A1 notation, for instance
=IMPORTRANGE(INDIRECT("B" & 2), INDIRECT("C" & 2))
will produce the same result as
=IMPORTRANGE(B2, C2)
Since this produces the same result, we now just have to find a way to make INDIRECT work with ARRAYFORMULA
Use ADDRESS to build the parameters for INDIRECT
Next you want to use ADDRESS to build the A1 reference for INDIRECT. For the current purposes, ADDRESS takes a numerical value for row and column as parameters
=INDIRECT(ADDRESS(2,2))
will produce the same result as
=INDIRECT("B" & 2)
Since these two are interchangeable, now we just need to find a way to get the numerical row and column values out of ARRAYFORMULA.
Call ADDRESS using the ROW and COLUMN functions
From there, you can get the row and column indexes from standard A1 notation using the ROW and COLUMN functions. While this may seem like we're pointlessly going in circles, the difference now is that ROW and COLUMN perform as expected with the ranges provided by ARRAYFORMULA. So given that ADDRESS will return $B$2 using using either method below
=ADDRESS(2,2)
or
=ADDRESS(ROW(B2),COLUMN(B2))
we now know that
=ARRAYFORMULA(ADDRESS(ROW(B2:B4),COLUMN(B2:B4)))
will produce the following array of addresses
{ $B$2; $B$3; $B$4 }
Final Assembly
So when we put this all together, we get
=ARRAYFORMULA(IMPORTRANGE(
INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)),
INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4))
)
where INDIRECT(ADDRESS(ROW(B2:B4), COLUMN(B2:B4)) is more or less interchangeable with what you might expect from B2:B4 inside ARRAYFORMULA and represents the url parameter
and INDIRECT(ADDRESS(ROW(C2:C4), COLUMN(C2:C4)) is roughly interchangeable with what you might expect from C2:C4 inside ARRAYFORMULA and represents the range parameter.
Suggestions on organization
I recommend using the indentation (Alt +Enter to create a new line ) above along with your indentation of choice to keep it easier to read. In the end it's just a bit more syntactic sugar and if spaces are used well it shouldn't be much harder to understand and make changes to 6 months later.
RE: Permissions - as mentioned by Atiq Zabinski, just placing a simple
IMPORTRANGE("http:/xxxx", "A1") somewhere on the sheet will provide a
means to know if the sheet is connected or not and the error message
should give you a context menu for connecting the sheet. You'll might
want to stay away from error handling in these scenarios as it will
slow down the process of connecting the sheets.

"Formula parse error" when querying different document

I am attempting to have a cell in Sheet B display data from a cell in External / Remote Sheet A, but it results in "Formula parse error." (ETA detail to aid searches: displaying data in one Google Spreadsheet from a different Google Sheet.)
My query:
=Query(SheetA,sheet1!A:I,"select I WHERE A=3")
I've also tried it this way:
=Query(SheetA,sheet1!$A:$I,"select I WHERE A=3",-1)
This answer courtesy of #AdamL (thank you, sir!). This was his answer that I found does work very well. When QUERY isn't directly referencing a range in the same spreadsheet, use Colx notation rather than column letters:
=QUERY(importrange("NameofGoogleSheet","SheetTabName!A:Z"),"select Col9 where Col1=3")
If referencing dynamically, use something like:
=QUERY(importrange("NameofGoogleSheet","SheetTabName!A:Z"),"select Col9 where Col1="&D19)
It is also important to note that you must first connect the sheets to each other. Until this is done, you will get column errors, etc. This is done by selecting a cell of the sheet that will display the data, and putting in an IMPORTRANGE on it, which opens a dialog for connecting them. More info: https://support.google.com/docs/answer/3093340?hl=en
I also realized (duh) that I was being stupid to have two separate files for each. I only need two sheets within the same document; 1 to serve as the database and the other to display the formatted data. I am using this for a pedigree application.
I had a Formula Parse Error problem. My mistake was that I had two brackets on my formula. I deleted one set, and it was fixed. I am not sure why, but it worked for me.
EXAMPLE:
=SUM((AB450,AB432,AB422,AB415,AB405)) - THIS GAVE ME A FORMULA PARSE ERROR.
=SUM(AB450,AB432,AB422,AB415,AB405) - THIS IS THE ONE THAT WORKED

Unable to use QUERY in google sheets when referencing cell as a value

I am working on a spreadsheet in google sheets that tries to do the following.
Retrieves a table by scraping a website.
Uses a query within that table to retrieve a specific value in the table.
Uses an existing cell in the spreadsheet to determine the value to match.
You can see the spreadsheet here. Cell D2 is the one in question. It attempts to use the C2 value to build a query. It doesn't work for some reason. I believe I have the correct syntax, but I'm not sure. Directly below in Cell D3 is the same formula with the value directly entered rather than referring to the cell.
I am getting an error that says "query completed with an empty output", which doesn't make sense to me when it works with the value directly inputted.
I figured this out, I was using the syntax incorrectly. The correct formula goes like this.
=query(importhtml(B2,"table",1),"select Col4 where Col8 ="&C2,1)
I imagine it was throwing an error because the second & symbol would lead it to believe that more text was coming and there was none.

Resources