I was able to find a way to solve my problem (detailed herehere) using an Apps Script with a custom function.
If you replace =IMPORTRANGE(spreadsheet_url, range_string)
in your spreadsheet with =DynamicImportRange(spreadsheet_url, sheet_name, range)
and paste the code below into Tools --> Script Editor --> Blank Project, it should work (see this for more information on writing apps scripts).
/**
Usage: =DynamicImportRange(spreadsheet_url, sheet_name, range)
Compare to: =IMPORTRANGE(spreadsheet_url, range_string)
Where the given arguments are placeholders that should be replaced
by arguments specific to your use-case.
*/
function DynamicImportRange(sheet_url, sheet_name, sheet_range) {
var values = SpreadsheetApp.openByUrl(sheet_url).getSheetByName(sheet_name).getRange(sheet_range).getValues();
return values
};
/**
*/
function RefreshSheet() {
// Update the following two variables to suit your particular situation
var sheet_name = "sample_sheet_sheet"
var range = "A1"
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheet_name);
var formula1 = "Loading...";
var formula2 = sheet.getRange(range).getFormula().toString().replace('"', '\"');
// The following assumes that the data is being inserted into the sheet in the same
// location as it is in in the source sheet.
var form_range = formula2.split(",")[2].split("\"")[1];
sheet.getRange(form_range).clear();
sheet.getRange(range).setValue(formula1);
Utilities.sleep(245);
sheet.getRange(range).setValue(formula2);
};
If you want the sheet to be updated on a regular basis, you can set up a trigger by going to Resources --> Current project's triggers in the Apps Script window.