Is there a FORMULA
that will display the name of the file in a cell?
I've found scripts that will do it, formulas that will display the sheet name, but no luck finding a formula that will show the filename.
If I have to resort to the script, so be it. But I'd like to use formula if possible.
If this has been asked before, please point me to the post and I will delete this one.
Then save the code window, and go back to the sheet that you want to get its name, then enter this formula: =sheetName() in a cell, and press Enter key, the sheet name will be displayed at once.
Show Formulas instead of Value in the Entire Sheet Click the View option in the menu. Click on Show formulas option.
there is no such formula. current limitations of Google Sheets does not support getting sheet names by internal formulae only, so you will need to resort to a script. here are a few variations:
function SHEETNAME() {
return SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
}
function SHEETLIST() {
try {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets()
var out = new Array( sheets.length+1 ) ;
out[0] = [ "NAME" , "#GID" ];
for (var i = 1 ; i < sheets.length+1 ; i++ ) out[i] =
[sheets[i-1].getName() , sheets[i-1].getSheetId() ];
return out
}
catch( err ) {
return "#ERROR!"
}
}
function SHEET(input) {
try {
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets() ;
if( (input>0) && (input <= sheets.length)) return sheets[(input-1)].getName() ;
else return "invalid sheet #" ;
}
catch( err ) {
return "#ERROR!"
}
}
function SNAME(option) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet()
var thisSheet = sheet.getName();
if(option === 0){ // ACTIVE SHEET NAME =SNAME(0)
return thisSheet;
}else if(option === 1){ // ALL SHEET NAMES =SNAME(1)
var sheetList = [];
ss.getSheets().forEach(function(val){
sheetList.push(val.getName())
});
return sheetList;
}else if(option === 2){ // SPREADSHEET NAME =SNAME(2)
return ss.getName();
}else{
return "#N/A"; // ERROR MESSAGE
};
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With