Search code examples
if-statementgoogle-sheetsswitch-statementgoogle-sheets-formulaimportrange

Google Sheets Importrange statement in SWITCH


I'm using the importdata statement inside in Switch condition and it does not return anything nor give an error.

My formula:

=SWITCH(C5,"Desired Value",IMPORTRANGE("url to the google spreadsheet", "MyTab!A:E"),C5,"Another Value","Another Value Output")

So when it's "Desired Value" is prints nothing. If I write a separate IMPORTRANGE without SWITCH it works fine.

EDIT:

Example

Source File (from what I'm importing) link and the file with SWITCH statement link


Solution

  • drop the SWITCH and use IF like:

    =IF(B1="Tab1", IMPORTRANGE("19csOm3txsZ-RAUiDYbEJLmWUsm5b-Qk9vkMMdJZ6CqM", "TAB1!A1:A19"),
     IF(B1="Tab2", IMPORTRANGE("19csOm3txsZ-RAUiDYbEJLmWUsm5b-Qk9vkMMdJZ6CqM", "TAB2!A1:A19"), ))
    

    0