View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Henrich Henrich is offline
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