I want copy current sheet to new one and sheet name change.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sourceSheet = ss.getSheetByName('sheet_name'); <=== question 1
var copy = sourceSheet.copyTo(ss);
ss.setActiveSheet(copy);// set it active
ss.moveActiveSheet(ss.getNumSheets());// move it to the last position
copy.setName(' newSheetName is add 1 from current sheet name'); <== question 2
question 1:
I need current sheet name or ID.
question 2:
if current sheet name is '10', add 1 for new Sheet name
I don't know how to add string type of sheet name.
We can now get the length of the sheet name by subtracting TotalLength-Location. In our example the sheet name length is 140-132=8 characters. RIGHT(FilePath,TotalLength-Location) will then return the right most 8 characters of the FilePath, which gives us the sheet name.
To return the sheet name in a cell, use CELL, FIND and MID in Excel. There's no built-in function in Excel that can get the sheet name. 1. The CELL function below returns the complete path, workbook name and current worksheet name.
By default, Excel names worksheets Sheet1, Sheet2, Sheet3 and so on, but you can easily rename them.
Question 1:
The Id refer to the spreadsheet, the name refer to the sheet. If you want to get the name of the sheet, take a look at the documentation on sheet.getName() method.
To get the name the active sheet:
var actualSheetName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
Question 2:
You can use the substring method to get the last characters of the sourceSheet string and use parseInt method to manipulate the characters as int value.
Example: Your sheet's name is '10'. You only need the parseInt method like:
var temp = parseInt(sourceSheet);
temp += 1;
copy.setName(temp.toString());
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