How do I call a name range using a cell reference? - google-sheets

I want to call a Named Range in a Google Sheets Query.
The name range is called Jazz_It_Up_Btq
easily the name range is called by:
=query(NAMERANGENAME,"select B where A='"&Y9&"'")
but if I want to call the range from another cell in the sheet:
=query(A1,"select B where A='"&Y9&"'")
I get an error. I have confirmed spelling.
What am I missing?

In your case, how about using INDIRECT as follows?
Modified formula:
=query(indirect(A1),"select B where A='"&Y9&"'")
In this case, it supposes that the cell "A1" has the name of the named range which is Jazz_It_Up_Btq.
Reference:
INDIRECT

Related

How to have cell reference as part of argument in google sheet function

How can I include a cell reference and have it evaluated inside the argument of a Google Sheets function? For example:
=COUNTIFS(Sheet1!E:E,"\*D1\*")
In the above example, I want D1 to be replaced with the value of that cell so that the function becomes something like
=COUNTIFS(Sheet1!E:E,"\*blabla\*")
If D1 contains "blabla".
Try the following
=COUNTIFS(Sheet1!E:E,"\*"&D1&"\*")

modify number from cell reference in QUERY function (Google Sheets)

Is it possible to modify a number from a cell reference within the syntax of a QUERY function in Google Sheets without a helper cell/column?
If I have "5" in a cell, can I reference that cell and somehow subtract 1 when using the LIMIT option in the QUERY syntax so it returns four results?
I am including a sample sheet below as well as working and nonworking formulas.
link to sheet & cell
https://docs.google.com/spreadsheets/d/1lyCK5eIEQYjGFOxh5T_4BxeuDS-1zvMLq80IYn0dc38/edit#gid=1018697126&range=B1
working formula:
=QUERY(INDIRECT(currentTable),"limit "&B1&"",1)
nonworking attempt:
=QUERY(INDIRECT(currentTable),"limit "&B1&"-1",1)
You can just subtract 1 from B1 instead before passing it into the query.
=QUERY(INDIRECT(currentTable),"limit "&B1-1,1)
Output:

How to reference a different spreadsheet in HLOOKUP?

I try to reference another spreadsheet in the HLOOKUP formula but fail. I'm doing this like:
=HLOOKUP(A2,"https://docs.google.com/spreadsheets/d/1qOzV/","report!A2:B2",2,0)
where http... is the URL of another spreadsheet, report!... is the name of the tab in another spreadsheet and the data range.
This kind of referencing of another spreadsheet's URL works with =importrange("https://docs.google.com/spreadsheets/d/1qOzV/","report!A2:B2"), as I realized from different examples.
But with HLOOKUP while doing so I get an error:
Wrong number of arguments to HLOOKUP. Expected between 3 and 4 arguments, but got 5 arguments.
It seems, that the spreadsheet URL is counted as separate parameter.
How do I correctly reference the URL, the sheet name and the data range?
PS: I tried to chain HLOOKUP and importrange, as mentioned in https://stackoverflow.com/a/39305031/1992004 - but fail on it, got just #REF.
My formula was
=HLOOKUP(A2,IMPORTRANGE("https://docs.google.com/spreadsheets/d/1qOzV"; "report!$A$2:$B$2"),2,0)
you are searching the content of cell A2 against imported range A2:B2 and if the match is found you returning the 1st row (of the whole dataset) of imported range after match eg. that's cell B2 of report!$A$2:$B$2. in other words range A2:B2 is one row so you cant return 2nd row from the one-row matrix, therefore valid formula is:
=HLOOKUP(A2,IMPORTRANGE("1I69LQ37hA5NjjJmuwmWkrDI_daiU_cnYDrUBpMm","report!$A$2:$B$2"),1,0)

Google spreadsheets: conditional formatting with custom formula based on values from different sheet

I have a google spreadsheet with two sheets. On the first sheet, the items are listed in column A, and their types are in column B.
On the second sheet, I reference to the first sheet's column A with the formula: =UNIQUE(Sheet1!A:A).
Then I want to color the items in the 2nd sheet based on the item type (1st sheet's column B*). I try to add conditional formatting using the formula =Sheet1!$B:$B="Type1", but when I try to save rules, it says the formula is invalid.
What would be the correct formula for this case?
You cannot reference cells directly in the conditional format formula. Also, I do not think that formula would work.
First, you need the VLOOKUP function to get the object's type.
Here's an example of using this function. The difference would be that the corresponding data in the first parameter would be preceded by the sheet name in your case.
See this image:
As you can see, VLOOKUP searchs for the item from D in the matrix A2:B4, and then returns the corresponding value (the value in the same row) in the second column of the matrix, which is column B.
So if you to apply this formula to conditional formatting, you would have:
=VLOOKUP($D$2:$D;$A$2:$B$4;2)="Dragon"
The first parameter of VLOOKUP has to be a range, and I started it from D2 so it would not match the header. In your case, it would become:
=VLOOKUP($D$2:$D;Sheet1!$A$2:$B$4;2)="Dragon"
But as you cannot use references directly, you need to use the INDIRECT function. It receives a cell range as a string and returns a reference to that range. It's the same as using references directly, but in this case you add an extra step (go figure). So the formula finally becomes:
=VLOOKUP($D:$D;INDIRECT("$A$2:$B$4");2)="Dragon"
You can choose any range to apply the format if you are using the new version of Spreadsheets. You could, for example, color the entire row or just a single cell.

how to concatenate a section of a column of data

Is it possible to use a cell to define the end of a range for a formula?
Essentially, I would like to use the JOIN() statement to concatenate a section of a column of data.
The data starts at a cell, say A5, and runs to a cell with the word 'total' in it. I've created a cell (let's call it L12) which returns the number of rows of data that are available.
I'd like to use that cell to form part of the range details of the JOIN() formula thus:
=JOIN(" ", A5: A[the value in L12]).
Is this possible?
I've found the indirect() function does exactly what I needed it to do.
See the Google function list https://support.google.com/docs/bin/static.py?hl=en&topic=25273&page=table.cs

Resources