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

My code is having trouble assigning a new name to a worksheet. I thought
this would work ws2.Name = ws1.Range("L4"). Cell "L4" on ws1 contains the
function TODAY(). I thought this would go ahead and assign todays date to
the name of ws2. The code breaks and the run time error does mention I
cannot use any / \ * etc. in the name. I tried to format the date to
something like 3-10-06 but to no avail. What the heck is wrong with this
simple request?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Trouble naming worksheet

Give this a whirl...

Sub test()
Dim wks As Worksheet
Dim strName As String

Set wks = Sheet2
strName = Format(Date, "mm-dd-yyyy")
If SheetExists(strName) Then
MsgBox "Sheet " & strName & " already exists."
Else
wks.Name = strName
End If

End Sub

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function
--
HTH...

Jim Thomlinson


"Coal Miner" wrote:

My code is having trouble assigning a new name to a worksheet. I thought
this would work ws2.Name = ws1.Range("L4"). Cell "L4" on ws1 contains the
function TODAY(). I thought this would go ahead and assign todays date to
the name of ws2. The code breaks and the run time error does mention I
cannot use any / \ * etc. in the name. I tried to format the date to
something like 3-10-06 but to no avail. What the heck is wrong with this
simple request?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Trouble naming worksheet

Maybe...

ws2.Name = format(ws1.Range("L4").value, "YYYY_MM_DD")

or just

ws2.Name = format(date, "YYYY_MM_DD")



Coal Miner wrote:

My code is having trouble assigning a new name to a worksheet. I thought
this would work ws2.Name = ws1.Range("L4"). Cell "L4" on ws1 contains the
function TODAY(). I thought this would go ahead and assign todays date to
the name of ws2. The code breaks and the run time error does mention I
cannot use any / \ * etc. in the name. I tried to format the date to
something like 3-10-06 but to no avail. What the heck is wrong with this
simple request?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Trouble naming worksheet

Dave and Jim,

Thanks. All is well now!

"Dave Peterson" wrote:

Maybe...

ws2.Name = format(ws1.Range("L4").value, "YYYY_MM_DD")

or just

ws2.Name = format(date, "YYYY_MM_DD")



Coal Miner wrote:

My code is having trouble assigning a new name to a worksheet. I thought
this would work ws2.Name = ws1.Range("L4"). Cell "L4" on ws1 contains the
function TODAY(). I thought this would go ahead and assign todays date to
the name of ws2. The code breaks and the run time error does mention I
cannot use any / \ * etc. in the name. I tried to format the date to
something like 3-10-06 but to no avail. What the heck is wrong with this
simple request?


--

Dave Peterson

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
Worksheet naming Woodstock Excel Discussion (Misc queries) 3 January 20th 09 10:35 PM
Naming Worksheet tabs Scott@CW Excel Discussion (Misc queries) 11 August 2nd 07 08:36 AM
Naming Worksheet Denis New Users to Excel 2 September 13th 05 05:55 PM
Naming a worksheet help? pauldaddyadams Excel Worksheet Functions 1 August 9th 05 10:46 AM
Trouble Naming Range Michael Smith Excel Programming 3 February 24th 05 05:46 PM


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