#1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Worksheet Name

I would like to have a worksheet automatically names itself whatever is in
cell a1....

What I would really like to do --

I need to create a payment request sheet for every 14 days... I have to show
the date at the top of each form. Rather than going in and typing the date I
want to see there, I would like each tab (and cell a1) to automatically
create itself... for instance, if sheet 1 is "9-7-2007", sheet 2 should read
"9-21-2007".

Any thoughts?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,365
Default Worksheet Name

Takes some code to do this. The code goes into the workbook code module. To
get to the right place: right-click on the Excel icon immediately to the left
of the word File in the Excel menu toolbar. Then choose [View Code] from the
list that pops up. Copy the code below and paste it into the module.

There is at least one restriction imposed by one of these routines - you
can't use the left parenthesis character [ ( ] as part of a worksheet name.
The code will see that and try to rename any sheet with it in the name.


Private Sub Workbook_NewSheet(ByVal Sh As Object)
'this will generally work when you use Insert | Worksheet
Dim anySheet As Worksheet
Dim latestDate As Date

latestDate = "1/1/1910" ' any very early date will do
For Each anySheet In Worksheets
If anySheet.Name < Sh.Name Then
'not our new sheet, check for date
If Not IsEmpty(anySheet.Range("A1")) And _
IsDate(anySheet.Range("A1")) Then
If anySheet.Range("A1") latestDate Then
latestDate = anySheet.Range("A1")
End If
End If
End If
Next ' examine next possible worksheet
'add 14 days to latest date
latestDate = latestDate + 14
'set format as d-Mon-YY
Sh.Range("A1").NumberFormat = "[$-409]d-mmm-yy;@"
Sh.Range("A1") = latestDate
Sh.Name = Sh.Range("A1").Text
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'this method prevents you from using the ( character as
'part of a sheet name because it's looking for that
'character to determine if this is a copy of another
'worksheet.
'
'this works when copying sheets.
'
Dim newDate As Date
If InStr(Sh.Name, "(") Then
'may be a sheet we need to rename
'check if there is a date in A1
If Not IsEmpty(Range("A1")) And _
IsDate(Range("A1")) Then
Range("A1") = Range("A1") + 14
Sh.Name = Range("A1").Text
End If
End If
End Sub


"Difficult1" wrote:

I would like to have a worksheet automatically names itself whatever is in
cell a1....

What I would really like to do --

I need to create a payment request sheet for every 14 days... I have to show
the date at the top of each form. Rather than going in and typing the date I
want to see there, I would like each tab (and cell a1) to automatically
create itself... for instance, if sheet 1 is "9-7-2007", sheet 2 should read
"9-21-2007".

Any thoughts?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 3,365
Default Worksheet Name

These two routines should cover most cases, one takes care of when you copy
an existing sheet (presumes you're copying the latest one), the other deals
with inserting a new worksheet into the workbook.

One restriction is imposed: you can't use the left parenthesis character [ (
] in a sheet name - the code will see it and try to rename it.

To put this code into the right place: right-click on the Excel icon to the
immediate left of the word File in the Excel menu toolbar. Choose [View
Code] from the list that appears. Copy the code below and paste it into the
module presented to you.


Private Sub Workbook_NewSheet(ByVal Sh As Object)
'this will generally work when you use Insert | Worksheet
Dim anySheet As Worksheet
Dim latestDate As Date

latestDate = "1/1/1910" ' any very early date will do
For Each anySheet In Worksheets
If anySheet.Name < Sh.Name Then
'not our new sheet, check for date
If Not IsEmpty(anySheet.Range("A1")) And _
IsDate(anySheet.Range("A1")) Then
If anySheet.Range("A1") latestDate Then
latestDate = anySheet.Range("A1")
End If
End If
End If
Next ' examine next possible worksheet
'add 14 days to latest date
latestDate = latestDate + 14
'set format as d-Mon-YY
Sh.Range("A1").NumberFormat = "[$-409]d-mmm-yy;@"
Sh.Range("A1") = latestDate
Sh.Name = Sh.Range("A1").Text
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'this method prevents you from using the ( character as
'part of a sheet name because it's looking for that
'character to determine if this is a copy of another
'worksheet.
'
'this works when copying sheets.
'
Dim newDate As Date
If InStr(Sh.Name, "(") Then
'may be a sheet we need to rename
'check if there is a date in A1
If Not IsEmpty(Range("A1")) And _
IsDate(Range("A1")) Then
Range("A1") = Range("A1") + 14
Sh.Name = Range("A1").Text
End If
End If
End Sub

"Difficult1" wrote:

I would like to have a worksheet automatically names itself whatever is in
cell a1....

What I would really like to do --

I need to create a payment request sheet for every 14 days... I have to show
the date at the top of each form. Rather than going in and typing the date I
want to see there, I would like each tab (and cell a1) to automatically
create itself... for instance, if sheet 1 is "9-7-2007", sheet 2 should read
"9-21-2007".

Any thoughts?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default Worksheet Name

This worked great! Thanks a million!

"JLatham" wrote:

Takes some code to do this. The code goes into the workbook code module. To
get to the right place: right-click on the Excel icon immediately to the left
of the word File in the Excel menu toolbar. Then choose [View Code] from the
list that pops up. Copy the code below and paste it into the module.

There is at least one restriction imposed by one of these routines - you
can't use the left parenthesis character [ ( ] as part of a worksheet name.
The code will see that and try to rename any sheet with it in the name.


Private Sub Workbook_NewSheet(ByVal Sh As Object)
'this will generally work when you use Insert | Worksheet
Dim anySheet As Worksheet
Dim latestDate As Date

latestDate = "1/1/1910" ' any very early date will do
For Each anySheet In Worksheets
If anySheet.Name < Sh.Name Then
'not our new sheet, check for date
If Not IsEmpty(anySheet.Range("A1")) And _
IsDate(anySheet.Range("A1")) Then
If anySheet.Range("A1") latestDate Then
latestDate = anySheet.Range("A1")
End If
End If
End If
Next ' examine next possible worksheet
'add 14 days to latest date
latestDate = latestDate + 14
'set format as d-Mon-YY
Sh.Range("A1").NumberFormat = "[$-409]d-mmm-yy;@"
Sh.Range("A1") = latestDate
Sh.Name = Sh.Range("A1").Text
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'this method prevents you from using the ( character as
'part of a sheet name because it's looking for that
'character to determine if this is a copy of another
'worksheet.
'
'this works when copying sheets.
'
Dim newDate As Date
If InStr(Sh.Name, "(") Then
'may be a sheet we need to rename
'check if there is a date in A1
If Not IsEmpty(Range("A1")) And _
IsDate(Range("A1")) Then
Range("A1") = Range("A1") + 14
Sh.Name = Range("A1").Text
End If
End If
End Sub


"Difficult1" wrote:

I would like to have a worksheet automatically names itself whatever is in
cell a1....

What I would really like to do --

I need to create a payment request sheet for every 14 days... I have to show
the date at the top of each form. Rather than going in and typing the date I
want to see there, I would like each tab (and cell a1) to automatically
create itself... for instance, if sheet 1 is "9-7-2007", sheet 2 should read
"9-21-2007".

Any thoughts?

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
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Charts and Charting in Excel 3 August 24th 06 07:26 PM
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Excel Discussion (Misc queries) 2 August 24th 06 05:26 PM
plot graph from multiple worksheet as embedded chart object on every worksheet [email protected] Excel Worksheet Functions 2 August 24th 06 05:26 PM
plot graph from multiple worksheet as embedded chart object on every worksheet jeftiong New Users to Excel 0 August 23rd 06 01:50 PM
Upload multiple text files into 1 excel worksheet + put the filename as the first column in the worksheet Aster Excel Worksheet Functions 3 March 12th 06 09:58 AM


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

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

About Us

"It's about Microsoft Excel"