View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dreiding Dreiding is offline
external usenet poster
 
Posts: 80
Default On Error action inconsistent

Through VBA, I enabling the use to add another worksheet and and change it's
name. I'm hoped to use the "On Error" trapping to continue looping asking
for valide worksheet name. My problem is that the error is trapped only
once. The second time around the error no longer trapped. What's the
correct way to use "On Error" to achieve my goal? Here's the code. Thanks
- Pat

Sub AddWorkSheet()
Dim vResponse As Variant

Sheet1.Copy After:=Sheets(Sheets.Count)

On Error GoTo BadName:
BadName:
vResponse = Trim(InputBox("New worksheet name? ", , ActiveSheet.Name))
If vResponse < "" Then
ActiveSheet.Name = vResponse
End If

On Error GoTo 0
End Sub