Google-sheets – How to reference a cell for the sheet name in IMPORTRANGE function in Google Sheets when the sheet is in another workbook

google sheetsimportrange

I have two workbooks with several sheets in each. I have a dropdown to select the sheet name that I'm using for reference for URLs and to reference other sheets in the main book.

I successfully used IMPORTRANGE to get data from the other workbook when I put the sheet name in it.

=IMPORTRANGE("https://docs.google.com/spreadsheets/d/12Up9RK9bveEPN35iXq3V1QouJMgXELgzzoOdLnID5lU/edit?usp=sharing", "AMT!B2:M8")

AMT needs to be replaced with the value from another cell.

I've referenced cells in other sheets using INDIRECT

, but not sure how to do it in this case in this particular string.

I've tried doing it a number of different ways, and this is my most recent attempt

=IMPORTRANGE("https://docs.google.com/spreadsheets/d/12Up9RK9bveEPN35iXq3V1QouJMgXELgzzoOdLnID5lU/edit?usp=sharing", "INDIRECT("'"&D4&"'!B2:M8")")

Best Answer

You do not need the INDIRECT function in your formula.

All you need to do is use

=IMPORTRANGE("JUST_THE_ID_HERE", ""&D4&"!B2:M8")

(where D4 holds AMT or is a cell using a Data Validation dropdown list)