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

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.

Related

my =Importrange Formula on Google sheet doesn't work with multiple Xlookups in the sheet

I'm making a budget sheet on google sheets. When I use importrange on my google sheet, it works perfectly fine. However when I use an Xlookup in a different tab and different cell, the Importrange fails and gets stuck on loading. I'm not sure why... It may be because they loosely reference each other? I'm using Xlookups to sum a range which includes some of the imported data... But in my mind, that shouldn't affect the Importrange at all. If you delete all the xlookups, the importrange pushes through, and if there is only 1 Xlookup in the entire sheet, Importrange still works... Can anyone help??? I've linked the sheet below so that you can play with it. You can change the links for the importrange freely.
FYI you have to delete the importrange / refresh the page after each change as the importrange will just keep the data their until there is a change on either the data side or sheet side.
Link to the Sheet
I tried deleting all Xlookups and and changing the Importange Range to lessen the impact
I tried array constraining other formulas in the sheet because I thought it was stuck on too many calculations
I tried simplifying the Xlookup formulas to set ranges.
you can build your IMPORTRANGE like:
=ARRAYFORMULA(IFERROR(NOW()/0)&IMPORTRANGE(D2; "A1:A4"))
and with:
changes won't be instant of course but they will flow more often

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

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(...)))

how can I write a formula that uses a cell's contents when building a range reference to the name of another sheet?

I have a large Google Sheets spreadsheet that has individual sheets for financial statements of activity for multiple years. I want to reference particular columns of those in other sheets, and I've successfully figured out how to do that with an HLOOKUP function. However, because I want to do this for multiple years, I'd like that HLOOKUP function to pick up the name of the sheet to reference from its column header. Right now, I'm hard-coding it like this—you can see the HLOOKUP range refers to cells in the "2021 Overall" sheet. The hard-coded approach works but makes adding a new year tedious. Ideally, the HLOOKUP formula would read the contents of its column header cell to determine which year it is.
As best I can tell, the solution is to use INDIRECT, but I can't figure out any way to build the formulate with INDIRECT and not get an error. For instance, this seemed like it should work. As you can see, I have 2021 in cell D4, and my INDIRECT statement is referencing that and building the rest of the range.
I've also tried using INDIRECT with an explicit CONCATENATE, with no more success.
Any ideas for how to look up that D4 cell and slide it into the HLOOKUP range?
Thank you!
Try to remove the "'"& before D4 and the ' after the Overall.
Your formula should look like this:
=IFERROR(HLOOKUP($A$2,INDIRECT(F4 &" Overall!$A$5:$X$150", Utility!$A10, FALSE)))
With Nikko's nudges in the right direction, I eventually figured out the right format. This allows the formula to work in multiple sheets and to be filled right (for more years) and down (for more classes).
=IFERROR(HLOOKUP($A$2,INDIRECT("'"D$4&" Overall'!$A$5:$X$150"), Utility!$A3, FALSE))
Note that if you try to replicate this, you may need to type the formula out from scratch—I had a problem where pasting it in didn't work. Once I'd retyped it and Google Sheets acknowledged it, it worked from then on in the spreadsheet, even when pasted from sheet to sheet.

Conditional formatting using countif() with values from an external spreadsheet

I have a Google sheet the references values from another and using conditional formatting, it marks down the cells with the same value. Within the same document, I use the following code:
=countif(indirect("Responses!D2:D103"),A1)=1 That works great.
However, I try to get the same result referencing the same sheet from an external spreadsheet to no avail. I feel like I tried all the combinations of IMPORTRANGE and INDIRECT out there, similar to this: =countif(importrange("sheet_url",indirect("Responses!$D$2:$D$103")),A1)=1
I'm sure I'm missing some small detail, I just can't tell what it is.
try:
=INDEX(COUNTIF(IMPORTRANGE("1ddqnVB9eDkk2tCadotN0NQlZdJDzIX4UyEEuXVs99nk",
"Responses!D1:D103"), A1)=1)
note that access needs to be granted first in order for this to work

COUNTIF and IMPORTRANGE returning 0

I would like to use the COUNTIF and IMPORTRANGE functions in Google Sheets, but the results keep returning 0. Here's my formula:
=COUNTIF(IMPORTRANGE("sheet key","PDFs!A2:A13"), "Yes")
There are no permission restrictions on the sheet I am trying to query, though I might restrict it to specific people.
I've tried the formula using the key and the sheet URL.
I've tested the formula with a tab in the same sheet and it works. Here is the formula I used:
=COUNTIF(PDFs!A2:A13,"Yes")
Any thoughts on why the COUNTIF/IMPORTRANGE formula isn't working?
Would restricting permissions make the formula not work?
Yes, specific authorisation is necessary and no, you don't need the sheet name as well as the key.
Try just:
=IMPORTRANGE("sheet key","A2:A13")
which should ask you for authorisation (if required) and grant it (if necessary). Then replace above with:
=COUNTIF(IMPORTRANGE("sheet key","A2:A13"),"Yes")
First use core Importrange formula Importrange("Key","Sheet!A2") and allow access. Once sheet gets the access then apply the whole formula, i.e countif(importrange("key","Sheet!A2:A),"Yes")

Resources