|Excel And SQL .com|
Home > VBA Macros
How to rename or delete a worksheet
If you need to rename a worksheet for any reason, you can do so by using the worksheet's rename method.
There are many situations, where you like to use temporary worksheets to perform various actions on your to support the functionality you would like to achive on your main worksheets. And at the end of the process you probably need to delete these temporary sheets created for your intermediate processing steps. You can do this by using worksheets delete method.
Sub Demo() 'If a worksheet named Sheet1 exists, rename it to "Sheet A" if (thisworkbook.worksheets("Sheet1") is nothing) then msgbox "Worksheet Sheet1 does't exist" else thisworkbook.worksheets("Sheet1").Name = "Sheet A" end if 'If a worksheet named Sheet3 exists, delete it if (thisworkbook.worksheets("Sheet3") is nothing) then msgbox "Worksheet Sheet3 does't exist" else thisworkbook.worksheets("Sheet3").delete end if End Sub
|© All Rights Reserved. ExcelAndSql.com|