Google Sheets IMPORTRANGE – How to Refer to a Cell Value

google sheetsimportrange

I am using this formula to bring data from another spreadsheet file based on name of the month. This time for February..

=query(importrange("1L86iP0GLHTubwfvxs1kJ4ocbmgRAd4Iz0000000M","'February'!A2:F"),"Select Col6, Col5 where Col1 is not null",0)

But I would like to type the cell that has the month name instead of writing the month manually in each formula. If the cell C1="February" in file A and C1="January" in file B, how can I write C1 instead of month name in the formula? for example like this:

=query(importrange("1L86iP0GLHTubwfvxs1kJ4ocbmgRAd4Iz000000jbcM","'C1'!A2:F"),"Select Col6, Col5 where Col1 is not null",0)

Best Answer

Judging from your formula, February or January must be tab names belonging to the spreadsheet.

If that is the case, use the following syntax

=query(importrange("1L86iP0GLHTubwfvxs1kJ4ocbmgRAd4Iz0000000M", C1&"!A2:F"),"Select Col6, Col5 where Col1 is not null",0)

where cell C1 has a value of February or January or...

(If still in trouble please explain better or share a test sheet.)