Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default clearing VBA worksheet names

I have a VBA program that, when executed, deletes all the worksheets in a workbook and creates new ones. Each time I execute this, the worksheet names ("Sheet1", "Sheet2", etc) aren't cleared...that is, if Sheet1 through Sheet25 are deleted, the new sheets start at Sheet26...even if I close Excel and reopen the workbook. How do I get the newly created sheets to restart at Sheet1?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default clearing VBA worksheet names

Something like?

Dim sh As Worksheet
Dim i As Long

On Error Resume Next
Application.DisplayAlerts = False
For Each sh In ActiveWorkbook.Worksheets
sh.delete
Next
ActiveSheet.Name = "Sheet1"
i = 2
Worksheets.Add.Name = "Sheet" & i
i = i + 1
Worksheets.Add.Name = "Sheet" & i


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Maynard" wrote in message
...
I have a VBA program that, when executed, deletes all the worksheets in a

workbook and creates new ones. Each time I execute this, the worksheet
names ("Sheet1", "Sheet2", etc) aren't cleared...that is, if Sheet1 through
Sheet25 are deleted, the new sheets start at Sheet26...even if I close Excel
and reopen the workbook. How do I get the newly created sheets to restart
at Sheet1?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default clearing VBA worksheet names

Doesn't Worksheet.Name change the worksheet name on the Excel side, and not on the VBA side? I'm not worried about the Excel side, but the VBA side. In other words, I am creating a new worksheet with Worksheet.Name = "MyData" (for example)...but on the VBA side, it's (Name) is Sheet592. I'm just worried I'm going to bump up against some limit if I don't practice clearing out the worksheet names on the VBA side.

Thanks.

"Bob Phillips" wrote:

Something like?

Dim sh As Worksheet
Dim i As Long

On Error Resume Next
Application.DisplayAlerts = False
For Each sh In ActiveWorkbook.Worksheets
sh.delete
Next
ActiveSheet.Name = "Sheet1"
i = 2
Worksheets.Add.Name = "Sheet" & i
i = i + 1
Worksheets.Add.Name = "Sheet" & i


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Maynard" wrote in message
...
I have a VBA program that, when executed, deletes all the worksheets in a

workbook and creates new ones. Each time I execute this, the worksheet
names ("Sheet1", "Sheet2", etc) aren't cleared...that is, if Sheet1 through
Sheet25 are deleted, the new sheets start at Sheet26...even if I close Excel
and reopen the workbook. How do I get the newly created sheets to restart
at Sheet1?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
using the Excel generic worksheet names instead of user-given names in code Paul Excel Discussion (Misc queries) 5 June 26th 09 08:44 PM
Clear a worksheet without clearing formulas? doodah Excel Discussion (Misc queries) 5 January 23rd 07 06:45 PM
Worksheet clearing Macros? Arlen Excel Discussion (Misc queries) 4 January 27th 05 04:04 PM
Exel VBA - Clearing clipboard, area names Timse Excel Programming 2 June 11th 04 09:35 AM
Clearing Dropdowns In A Worksheet Aechelon Excel Programming 2 October 24th 03 01:41 AM


All times are GMT +1. The time now is 05:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"