Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Autodate worksheet tab


Hi All ....

This is my first post on this board.

I currently use a small piece of code to automatically name a new
worksheet todays date. If I open a second worksheet on the same day, I
trap the error caused by duplicating the worksheet name and create a
message box telling me to rename the new worksheet.

This is the code I use (the first part sends the new worksheet to the
back of the workbook).


Private Sub Workbook_NewSheet(ByVal Sh As Object)
On Error GoTo lookout
Sh.Move After:=Sheets(Sheets.Count)
Sh.Name = Format(Date, "dd-mmm-yyyy")

Exit Sub

lookout:

MsgBox "Worksheet Called " & Format(Date, "dd-mmm-yyyy") & " Already
Exists ... Rename This WorkSheet."

End Sub

What I would like to do is, add an underscore plus a number after the
date if the worksheet of that date already exists. For example, the
first worksheet generated today is called 19-Aug-2006 and I would like
to call the next one generated today 19-Aug-2006_1, and so on, rather
than receive the message box telling me that a sheet of that name
already exists.

Any ideas out there??

Regards ..... g-fer.


--
G-fer
------------------------------------------------------------------------
G-fer's Profile: http://www.excelforum.com/member.php...o&userid=37756
View this thread: http://www.excelforum.com/showthread...hreadid=573380

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Autodate worksheet tab

I'd use a format of dd_mmm_yyyy_001, since it could make sorting the worksheets
easier.

Option Explicit
Private Sub Workbook_NewSheet(ByVal Sh As Object)

Dim iCtr As Long
Dim myStr As String

iCtr = 0
Do
Sh.Move After:=Sheets(Sheets.Count)
If iCtr = 0 Then
myStr = ""
Else
myStr = Format(iCtr, "_000")
End If
On Error Resume Next
Sh.Name = Format(Date, "dd-mmm-yyyy") & myStr
If Err.Number = 0 Then
Exit Do
End If
iCtr = iCtr + 1
Loop

End Sub

And if you ever want to sort the worksheets...

Chip Pearson's:
http://www.cpearson.com/excel/sortws.htm

David McRitchie's:
http://www.mvps.org/dmcritchie/excel...#sortallsheets

G-fer wrote:

Hi All ....

This is my first post on this board.

I currently use a small piece of code to automatically name a new
worksheet todays date. If I open a second worksheet on the same day, I
trap the error caused by duplicating the worksheet name and create a
message box telling me to rename the new worksheet.

This is the code I use (the first part sends the new worksheet to the
back of the workbook).

Private Sub Workbook_NewSheet(ByVal Sh As Object)
On Error GoTo lookout
Sh.Move After:=Sheets(Sheets.Count)
Sh.Name = Format(Date, "dd-mmm-yyyy")

Exit Sub

lookout:

MsgBox "Worksheet Called " & Format(Date, "dd-mmm-yyyy") & " Already
Exists ... Rename This WorkSheet."

End Sub

What I would like to do is, add an underscore plus a number after the
date if the worksheet of that date already exists. For example, the
first worksheet generated today is called 19-Aug-2006 and I would like
to call the next one generated today 19-Aug-2006_1, and so on, rather
than receive the message box telling me that a sheet of that name
already exists.

Any ideas out there??

Regards ..... g-fer.

--
G-fer
------------------------------------------------------------------------
G-fer's Profile: http://www.excelforum.com/member.php...o&userid=37756
View this thread: http://www.excelforum.com/showthread...hreadid=573380


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Autodate worksheet tab


Thanks Dave ...

I'll give it a try. Sorry about the duel post ... won't happen again.

G-fer.


--
G-fer
------------------------------------------------------------------------
G-fer's Profile: http://www.excelforum.com/member.php...o&userid=37756
View this thread: http://www.excelforum.com/showthread...hreadid=573380

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
Search one worksheet for values in another worksheet? ClayShooters Excel Discussion (Misc queries) 1 July 4th 06 03:01 PM
Worksheet not showing up in VBE Kevin Vaughn Excel Worksheet Functions 3 June 12th 06 03:22 PM
Inserting Filtered RC cell information into other worksheets Dennis Excel Discussion (Misc queries) 10 July 30th 05 01:54 AM
Search/Match between 2 x separate Worksheets and populate result in third worksheet Alan Bartley Excel Discussion (Misc queries) 1 April 11th 05 05:21 AM
Weekly Transaction Processing Ralph Howarth Excel Worksheet Functions 4 January 19th 05 05:37 AM


All times are GMT +1. The time now is 02:57 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"