Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Rename a worksheet

I have a workbook with 104 worksheets (2 worksheets for each week of the
year) which I use as a Template. Each worksheet has a date in cell A4. Each
year I have to create a new years workbook by changing the date on the 1st
worksheet (cell A4) (all other worksheets update based on the date on the
first worksheet). Is there any way to have each worksheet rename to the date
in its respective cell A4? The format would be dd mmm yy.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Rename a worksheet

For the first worksheet add


Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh As Sheet1
If Target.Address = "$A$4" Then
If IsDate(Target.Value) Then
For Each sh In ThisWorkbook.Worksheets
sh.Name = Format(sh.Range("A4").Value, "ddd-mm-yyyy")
Next sh
End If
End If
End Sub

This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Patrick Simonds" wrote in message
...
I have a workbook with 104 worksheets (2 worksheets for each week of the
year) which I use as a Template. Each worksheet has a date in cell A4.

Each
year I have to create a new years workbook by changing the date on the 1st
worksheet (cell A4) (all other worksheets update based on the date on the
first worksheet). Is there any way to have each worksheet rename to the

date
in its respective cell A4? The format would be dd mmm yy.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Rename a worksheet

Thanks for your reply

I tried your code and get the following error:

Run Time Error 13
Type mismatch

The following line is highlighted:

For Each sh In ThisWorkbook.Worksheets

One thig I should have noted was that Sheet One does not need to be renamed.
I tried deleteing Sheet one to see if it was causing the probem but still
got an error message:

Run Time Error 13
Type mismatch

The following line is highlighted:

Next sh

"Bob Phillips" wrote in message
...
For the first worksheet add


Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh As Sheet1
If Target.Address = "$A$4" Then
If IsDate(Target.Value) Then
For Each sh In ThisWorkbook.Worksheets
sh.Name = Format(sh.Range("A4").Value, "ddd-mm-yyyy")
Next sh
End If
End If
End Sub

This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Patrick Simonds" wrote in message
...
I have a workbook with 104 worksheets (2 worksheets for each week of the
year) which I use as a Template. Each worksheet has a date in cell A4.

Each
year I have to create a new years workbook by changing the date on the
1st
worksheet (cell A4) (all other worksheets update based on the date on the
first worksheet). Is there any way to have each worksheet rename to the

date
in its respective cell A4? The format would be dd mmm yy.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Rename a worksheet

I think Bob meant "Dim sh As Worksheet" instead of "Dim sh As Sheet1"

Regards,
Greg

"Patrick Simonds" wrote:

Thanks for your reply

I tried your code and get the following error:

Run Time Error 13
Type mismatch

The following line is highlighted:

For Each sh In ThisWorkbook.Worksheets

One thig I should have noted was that Sheet One does not need to be renamed.
I tried deleteing Sheet one to see if it was causing the probem but still
got an error message:

Run Time Error 13
Type mismatch

The following line is highlighted:

Next sh

"Bob Phillips" wrote in message
...
For the first worksheet add


Private Sub Worksheet_Change(ByVal Target As Range)
Dim sh As Sheet1
If Target.Address = "$A$4" Then
If IsDate(Target.Value) Then
For Each sh In ThisWorkbook.Worksheets
sh.Name = Format(sh.Range("A4").Value, "ddd-mm-yyyy")
Next sh
End If
End If
End Sub

This is worksheet event code, which means that it needs to be
placed in the appropriate worksheet code module, not a standard
code module. To do this, right-click on the sheet tab, select
the View Code option from the menu, and paste the code in.

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Patrick Simonds" wrote in message
...
I have a workbook with 104 worksheets (2 worksheets for each week of the
year) which I use as a Template. Each worksheet has a date in cell A4.

Each
year I have to create a new years workbook by changing the date on the
1st
worksheet (cell A4) (all other worksheets update based on the date on the
first worksheet). Is there any way to have each worksheet rename to the

date
in its respective cell A4? The format would be dd mmm yy.







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 information from one worksheet, to rename inserted worksheet Lyn Excel Worksheet Functions 0 March 24th 06 12:54 AM
why can't I rename my worksheet? cfc1905 Excel Discussion (Misc queries) 2 February 13th 06 03:19 PM
Rename Worksheet chin_un_len[_4_] Excel Programming 5 February 1st 06 06:56 PM
Rename the worksheet praveen_khm Excel Discussion (Misc queries) 1 January 17th 06 08:05 PM
rename worksheet Anthony Excel Discussion (Misc queries) 4 July 13th 05 01:16 AM


All times are GMT +1. The time now is 06:36 AM.

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"