LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 237
Default Duplicate sheet error handler

Below is a code that creates a worksheet. How would I get
it to display the error "Duplicate Sheet" and then exit
the sub if it detects a sheet with the name of the sheet
it is trying to create?

Right now if the name of the sheet already exsists when
the code trys to create a sheet I get the error "Run time
error 1004
Cannot rename a sheet to the same name as another sheet,
etc..."

Thanx

Todd

Dim sha As Worksheet
Dim shar As Worksheet

Set sha = Worksheets(1)
'Set shar = ActiveWorkbook.Worksheets.Add
With ActiveWorkbook.Worksheets
Set shar = .Add(after:=.Item(.Count))
End With

sha.Cells.Copy

shar.Cells.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False

shar.Cells.PasteSpecial Paste:=xlPasteFormats, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=False

shar.Name = sha.Range("E2").Value
shar.Range("A2").Select

ActiveWindow.DisplayZeros = False
Worksheets(1).Select
 
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
Error handler linto Excel Discussion (Misc queries) 1 February 11th 10 12:17 PM
Error Handler Question Jenny B. Excel Discussion (Misc queries) 4 January 9th 08 05:16 PM
Error Handler sharad Excel Discussion (Misc queries) 1 September 17th 07 06:38 PM
error handler Fleur Excel Programming 1 November 20th 03 06:06 AM
Error handler loop? zSplash Excel Programming 4 October 10th 03 11:00 PM


All times are GMT +1. The time now is 06:26 AM.

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"