Rename sheet based on cell value in Excel Online

stags81

New Member
Joined
Dec 10, 2010
Messages
19
Hello,

I am new to Excel Online scripts, and I'm trying to write a script that automatically renames a sheet based on the value in a cell on that sheet.

I assume I'd want to establish a variable with "let", so I'd think it would be something like the below. The Sheet Name, ideally, would be a date in mm-dd-yy format.

//Set Sheet1 (the original sheet name) to the value in cell H1

let = actualdate = sheet1.getRange("H1");
sheet1.setName(actual date);

Having issues since the setName function expects a string instead of a range. Can someone assist?

Thanks,

Mike
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
JavaScript:
function main(workbook: ExcelScript.Workbook) {
    let worksheet = workbook.getActiveWorksheet();
    let newName = worksheet.getRange("E1").getValue().toString();
    worksheet.setName(newName);
}

You are attempting to set the range object to a parameter expecting a string, which you cannot do. In order to get the necessary value in the correct type, you'll need to use some additional functions of the range object to narrow things down. You are already selecting the range (the object) with .getRange. However, you then want to get it's value property with .getValue. Lastly, you need to return the string representation of that value, accomplished with .toString
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top