Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
need error loop in pivot table routine | Excel Discussion (Misc queries) | |||
Error #1004 routine send emails | Excel Discussion (Misc queries) | |||
Error routine needed | Excel Programming | |||
Error Handling Routine | Excel Programming |