Skip to content
Advertisement

Google Sheets – Query from selected tab

I have multiple tabs with the same structure, and a query tab. There, I am using the following query formula:

=query({'Sheet1'!A2:L},"select * "&
IF(COUNTA(B2:B3)>0,"where "&
IF(B2="","","Col"& COLUMN('Sheet1'!B2) &" >= date '" & TEXT(B2,"yyyy-mm-dd") &"'")&
IF(B3="","",IF(COUNTA(B2)>0," and ","")&"Col"&
COLUMN('Sheet1'!B2) &" <= date '" & TEXT(B3,"yyyy-mm-dd")&"'"),""),1)

I have set cells B1:B3 with data validation:

  1. B2 will select the start date for the query
  2. B3 will select the end date for the query

I would like that B1 would determine the tab from which the query would select the data. For example, if B1 value is Sheet1, the query would select the data from Sheet1, and only show the data from Sheet1. If it is set as Sheet2, it would select from Sheet2, and so on.

Is there a way to do that?

Advertisement

Answer

Yes, you can use the INDIRECT() function

enter image description here

=query(indirect(B5),"SELECT *",1)

enter image description here

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement