Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 447
Default Error Routine

I am sure this is a simply question...but my macro is copying an exisiting
worksheet and having the user enter a name. When the name is the same as an
exisiting name, the user gets an error message, but the worksheet is still
created. What code will delete the worksheet if the name is wrong??

Thanks,
Karen......
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Error Routine

Hi Karen,

You could test for the existance of the sheet and skip the copy if the sheet
already exists.

Something like:

'================================
Sub Tester()
Dim res As String
res = InputBox("Please enter new sheet name")

If Not res = "" Then
If SheetExists(res) Then
'Skip copy
MsgBox "The " & res & " sheet already exists!"
Else
Sheets("Sheet1").Copy _
after:=ActiveWorkbook.Sheets(1)
ActiveSheet.Name = res
End If
Else
MsgBox "No name provided"
End If
End Sub

'---------------------------------

Function SheetExists(sName As String) As Boolean
On Error Resume Next
SheetExists = CBool(Len(Sheets(sName).Name))
On Error GoTo 0
End Function

'<<================================

---
Regards,
Norman



"Karen" wrote in message
...
I am sure this is a simply question...but my macro is copying an exisiting
worksheet and having the user enter a name. When the name is the same as
an
exisiting name, the user gets an error message, but the worksheet is still
created. What code will delete the worksheet if the name is wrong??

Thanks,
Karen......



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
need error loop in pivot table routine Jeff C Excel Discussion (Misc queries) 0 May 29th 08 11:08 AM
Error #1004 routine send emails Gus[_2_] Excel Discussion (Misc queries) 0 June 7th 07 01:23 AM
Error routine needed Jeff Wright[_2_] Excel Programming 1 April 21st 05 04:11 AM
Error Handling Routine kenrmcl Excel Programming 4 April 4th 04 11:50 AM


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