Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Not creating duplicating worksheets with the same name


I would like to write a macro that would create a workshee
automatically for the next year but how can i prevent it from creatin
a new worksheet everytime the macro is run.

i have work out some codes but i think it still need alot o
improvements.

i would need the program to create a worksheet for 2007 if today's yea
is 2006. which means the name of the worksheet would be next year.

Dim x As Integer
x = 2006

Workbooks("PEM_Master_Record.xls").Activate

If Year(Date) = x Then
Dim y As Worksheet
On Error Resume Next
Set y = Sheets([text(today(),"yyyy")])
If Err.Number = 0 Then Exit Sub
Application.ScreenUpdating = False
Set y = ActiveWorkbook.Worksheets.Add(after:=Sheets(Sheets .count))
y.Name = [text(today(),"yyyy")]
Application.ScreenUpdating = True
Set y = Nothing
End I

--
ReD-DevI
-----------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...fo&userid=3262
View this thread: http://www.excelforum.com/showthread.php?threadid=52560

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Not creating duplicating worksheets with the same name

Hi, try this:

Sub SheetAdd()
On Error GoTo line1:
x = "2006"
Sheets(x).Select
Exit Sub
line1:
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = x
End Sub

Henrich

€žReD-DevIL" napĂ*sal (napĂ*sala):


I would like to write a macro that would create a worksheet
automatically for the next year but how can i prevent it from creating
a new worksheet everytime the macro is run.

i have work out some codes but i think it still need alot of
improvements.

i would need the program to create a worksheet for 2007 if today's year
is 2006. which means the name of the worksheet would be next year.

Dim x As Integer
x = 2006

Workbooks("PEM_Master_Record.xls").Activate

If Year(Date) = x Then
Dim y As Worksheet
On Error Resume Next
Set y = Sheets([text(today(),"yyyy")])
If Err.Number = 0 Then Exit Sub
Application.ScreenUpdating = False
Set y = ActiveWorkbook.Worksheets.Add(after:=Sheets(Sheets .count))
y.Name = [text(today(),"yyyy")]
Application.ScreenUpdating = True
Set y = Nothing
End If


--
ReD-DevIL
------------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...o&userid=32624
View this thread: http://www.excelforum.com/showthread...hreadid=525600


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Not creating duplicating worksheets with the same name


Hi, thanks a lot for your help. But instead of giving "x" a fixed value
can we have a condition that once every first day of a new year it wil
automatically create a new worksheet. e.g. today is 01/01/06 then a ne
worksheet named 2007 is created, then once it is 01/01/07 a workshee
for 2008 will be added. Is that possible

--
ReD-DevI
-----------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...fo&userid=3262
View this thread: http://www.excelforum.com/showthread.php?threadid=52560

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Not creating duplicating worksheets with the same name

Hi, so use this:

x = DatePart("yyyy", Date)

Henrich

€žReD-DevIL" napĂ*sal (napĂ*sala):


Hi, thanks a lot for your help. But instead of giving "x" a fixed value,
can we have a condition that once every first day of a new year it will
automatically create a new worksheet. e.g. today is 01/01/06 then a new
worksheet named 2007 is created, then once it is 01/01/07 a worksheet
for 2008 will be added. Is that possible ?


--
ReD-DevIL
------------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...o&userid=32624
View this thread: http://www.excelforum.com/showthread...hreadid=525600


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Not creating duplicating worksheets with the same name

Hi, this should solve your problem:

Option Explicit
Sub SheetAdd()
Dim x As String
On Error GoTo line1:
x = DatePart("yyyy", Date)
x = x + 1
Sheets(x).Select
Exit Sub
line1:
Worksheets.Add.Move after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = x

End Sub

Henrich

€žHenrich" napĂ*sal (napĂ*sala):

Hi, so use this:

x = DatePart("yyyy", Date)

Henrich

€žReD-DevIL" napĂ*sal (napĂ*sala):


Hi, thanks a lot for your help. But instead of giving "x" a fixed value,
can we have a condition that once every first day of a new year it will
automatically create a new worksheet. e.g. today is 01/01/06 then a new
worksheet named 2007 is created, then once it is 01/01/07 a worksheet
for 2008 will be added. Is that possible ?


--
ReD-DevIL
------------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...o&userid=32624
View this thread: http://www.excelforum.com/showthread...hreadid=525600




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Not creating duplicating worksheets with the same name


Thanks a lot Henrich. :)
One more question, x = DatePart("yyyy", Date)
what does DatePart stands for

--
ReD-DevI
-----------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...fo&userid=3262
View this thread: http://www.excelforum.com/showthread.php?threadid=52560

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Not creating duplicating worksheets with the same name

Hi RD, please, do not hesitate and see help for further information.

Henrich

€žReD-DevIL" napĂ*sal (napĂ*sala):


Thanks a lot Henrich. :)
One more question, x = DatePart("yyyy", Date)
what does DatePart stands for ?


--
ReD-DevIL
------------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...o&userid=32624
View this thread: http://www.excelforum.com/showthread...hreadid=525600


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Not creating duplicating worksheets with the same name


Oh ok. Thanks anyway :

--
ReD-DevI
-----------------------------------------------------------------------
ReD-DevIL's Profile: http://www.excelforum.com/member.php...fo&userid=3262
View this thread: http://www.excelforum.com/showthread.php?threadid=52560

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
Multiple worksheets & duplicating formula Jackie New Users to Excel 7 February 15th 09 04:41 PM
Duplicating Cells across worksheets Ted K Excel Discussion (Misc queries) 2 August 11th 08 11:36 PM
duplicating values to different worksheets lester Excel Discussion (Misc queries) 1 July 27th 06 04:19 PM
Duplicating cell value between worksheets Dennis Excel Worksheet Functions 6 January 12th 06 03:42 AM
duplicating worksheets Ralph2 Excel Discussion (Misc queries) 1 January 20th 05 05:05 AM


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