View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] itsthedude@gmail.com is offline
external usenet poster
 
Posts: 14
Default On Error GoTo .... error

I have the following code which is supposed to enter a new worksheet,
rename it "Working Template" and do other stuff. There is an error
check that is supposed to flag the error that occurs if a "Working
Template" sheet already exists - then delete the current (newly added)
sheet and the "Working Template", then go back to the beginning. For
some reason, though, it's just not working at all. I wrote the code
on another computer and had no problems, but on this machine it
refuses to catch it. I could rewrite it to circumvent the problem,
but it is happening elsewhere too, so i would like to get a better
understanding of why.

Any advice or recommendations would be greatly appreciated.

Function ()
beginning:
Sheets.Add After:=Sheets(6)
On Error GoTo error_occured
Sheets(7).Name = "Working Template"
Sheets(6).Cells.Copy
Sheets(7).Select
With Selection
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With
Cells.UnMerge
Exit Function

error_occured:
Application.DisplayAlerts = False
ActiveSheet.Delete
Sheets("Working Template").Delete
Application.DisplayAlerts = True
Resume beginning
End Function

Thanks,
Thedude