![]() |
Insert A Worksheet using VBA
I have a workbook that I need to add a Worksheet called "CurWorkPad" to.
Right now I can insert a worksheet and it will come up named "Sheetx", where x=a number that increments each time a sheet is inserted. I also have code to rename a worksheet, but it requires you to know the current name of the inserted worksheet. Is there a way to insert a new worksheet and rename it at the same time without knowing what excel named the new worksheet? Thanks for any help. Mike |
Insert A Worksheet using VBA
when you insert the worksheet the new worksheet becomes selected
automatically, so you can use this to rename the new sheet ActiveSheet.Name = "New_Name" "Mike" wrote: I have a workbook that I need to add a Worksheet called "CurWorkPad" to. Right now I can insert a worksheet and it will come up named "Sheetx", where x=a number that increments each time a sheet is inserted. I also have code to rename a worksheet, but it requires you to know the current name of the inserted worksheet. Is there a way to insert a new worksheet and rename it at the same time without knowing what excel named the new worksheet? Thanks for any help. Mike |
Insert A Worksheet using VBA
Worked Great. Thanks.
Mike "flow23" wrote: Try this Sub addsheet() Sheets.Add.Name = "CurWorkPad" End Sub change " curworkpad" to any name you want "Mike" wrote: I have a workbook that I need to add a Worksheet called "CurWorkPad" to. Right now I can insert a worksheet and it will come up named "Sheetx", where x=a number that increments each time a sheet is inserted. I also have code to rename a worksheet, but it requires you to know the current name of the inserted worksheet. Is there a way to insert a new worksheet and rename it at the same time without knowing what excel named the new worksheet? Thanks for any help. Mike |
Insert A Worksheet using VBA
Try this
Sub addsheet() Sheets.Add.Name = "CurWorkPad" End Sub change " curworkpad" to any name you want "Mike" wrote: I have a workbook that I need to add a Worksheet called "CurWorkPad" to. Right now I can insert a worksheet and it will come up named "Sheetx", where x=a number that increments each time a sheet is inserted. I also have code to rename a worksheet, but it requires you to know the current name of the inserted worksheet. Is there a way to insert a new worksheet and rename it at the same time without knowing what excel named the new worksheet? Thanks for any help. Mike |
All times are GMT +1. The time now is 11:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com