Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Naming a Sheet with a function


I want to put in the sheet name tab the actual date. I have tried the
following macro but it does not work:
Sub nombrar()

Dim fecha As String

fecha = Date
ActiveCell.Value = fecha ‘this is only for testing that fecha is
a string with the date
ActiveSheet.Name = fecha

End Sub

I get an error in the last line. If I put fecha between quotes I get
the name fecha of course, insted of his value


--
MónicaM
------------------------------------------------------------------------
MónicaM's Profile: http://www.excelforum.com/member.php...o&userid=22523
View this thread: http://www.excelforum.com/showthread...hreadid=374562

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Naming a Sheet with a function

You probably have illegal characters in your date format (e.g., "/")

Try

ActiveSheet.Name = Format(Date, "dd-mmm-yyyy")

substitute your desired date format (with legal characters)



In article ,
MónicaM wrote:

I want to put in the sheet name tab the actual date. I have tried the
following macro but it does not work:
Sub nombrar()

Dim fecha As String

fecha = Date
ActiveCell.Value = fecha ‘this is only for testing that fecha is
a string with the date
ActiveSheet.Name = fecha

End Sub

I get an error in the last line. If I put fecha between quotes I get
the name fecha of course, insted of his value

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default Naming a Sheet with a function

Monica

You can't use / in a sheet name which is the problem. Try using the Format
function to format the date so that only legal characters are included.

Sub test()

Dim fecha As Date

fecha = Date

ActiveSheet.Name = Format(fecha, "yyyy_mm_dd")

End Sub

--
Dick Kusleika
Excel MVP
Daily Dose of Excel
www.dicks-blog.com

MónicaM wrote:
I want to put in the sheet name tab the actual date. I have tried the
following macro but it does not work:
Sub nombrar()

Dim fecha As String

fecha = Date
ActiveCell.Value = fecha ‘this is only for testing that fecha is
a string with the date
ActiveSheet.Name = fecha

End Sub

I get an error in the last line. If I put fecha between quotes I get
the name fecha of course, insted of his value



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Naming a Sheet with a function

Hi Monica,

Your sheet naming routing works fine for me. It would fail of course if
another sheet is named with today's date. If you need multiple sheets
similarly named with Date try this:

Sub test2()
Dim fecha As String
Dim sht As Object
n = Date
fecha = CStr(Date)
For Each sht In ActiveWorkbook.Sheets
If Left(sht.Name, Len(fecha)) = fecha Then
cnt = cnt + 1
End If
Next
If cnt Then fecha = fecha & Chr(65 + cnt)

ActiveSheet.Name = fecha
End Sub

Regards,
Peter T

"MónicaM" wrote in
message ...

I want to put in the sheet name tab the actual date. I have tried the
following macro but it does not work:
Sub nombrar()

Dim fecha As String

fecha = Date
ActiveCell.Value = fecha ‘this is only for testing that fecha is
a string with the date
ActiveSheet.Name = fecha

End Sub

I get an error in the last line. If I put fecha between quotes I get
the name fecha of course, insted of his value


--
MónicaM
------------------------------------------------------------------------
MónicaM's Profile:

http://www.excelforum.com/member.php...o&userid=22523
View this thread: http://www.excelforum.com/showthread...hreadid=374562



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Naming a Sheet with a function

Reading JE's & Dick's comments I realise your routine only worked for me
because my default/system date format is "dd-mm-yyyy", namely does not
include a "/".

Peter T

"Peter T" <peter_t@discussions wrote in message
...
Hi Monica,

Your sheet naming routing works fine for me. It would fail of course if
another sheet is named with today's date. If you need multiple sheets
similarly named with Date try this:

Sub test2()
Dim fecha As String
Dim sht As Object
n = Date
fecha = CStr(Date)
For Each sht In ActiveWorkbook.Sheets
If Left(sht.Name, Len(fecha)) = fecha Then
cnt = cnt + 1
End If
Next
If cnt Then fecha = fecha & Chr(65 + cnt)

ActiveSheet.Name = fecha
End Sub

Regards,
Peter T

"MónicaM" wrote in
message ...

I want to put in the sheet name tab the actual date. I have tried the
following macro but it does not work:
Sub nombrar()

Dim fecha As String

fecha = Date
ActiveCell.Value = fecha ‘this is only for testing that fecha is
a string with the date
ActiveSheet.Name = fecha

End Sub

I get an error in the last line. If I put fecha between quotes I get
the name fecha of course, insted of his value


--
MónicaM
------------------------------------------------------------------------
MónicaM's Profile:

http://www.excelforum.com/member.php...o&userid=22523
View this thread:

http://www.excelforum.com/showthread...hreadid=374562







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
Naming a sheet Mike Excel Discussion (Misc queries) 3 March 7th 07 08:43 AM
naming sheet tab artist4christ Excel Worksheet Functions 5 January 17th 07 11:54 PM
Naming Sheet mehare Excel Discussion (Misc queries) 4 August 14th 06 06:20 PM
Sheet naming Pat Excel Programming 7 December 15th 04 10:29 PM
Naming a new sheet. Rich Cooper Excel Programming 1 May 25th 04 09:56 PM


All times are GMT +1. The time now is 12:10 PM.

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"