Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default error runtime 9: deleting a worksheet

Hello,
I wrote following code and sometimes I get an runtime error 9. I don't
really know when and why this error occurs. The value of test is never
empty.


On Error GoTo Marke
Application.DisplayAlerts = False
test = Worksheets("Länderansicht").Range("A" & i).Value
''''''''FEHLER'''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets(test).Select ''''''''''HIER TRITT DER FEHLER AUF
'''''''FEHLER''''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets("Länderansicht").Select
Worksheets("Länderansicht").Activate
Worksheets(test).Delete
Marke:
Application.DisplayAlerts = True


Tanks a lot,
Michael
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default error runtime 9: deleting a worksheet

You would get this error if test does not match the name of a sheet in the
activeworkbook. (could be a spelling error or a matter of extra spaces or
example)

--
Regards,
Tom Ogilvy


wrote in message
om...
Hello,
I wrote following code and sometimes I get an runtime error 9. I don't
really know when and why this error occurs. The value of test is never
empty.


On Error GoTo Marke
Application.DisplayAlerts = False
test = Worksheets("Länderansicht").Range("A" & i).Value
''''''''FEHLER'''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets(test).Select ''''''''''HIER TRITT DER FEHLER AUF
'''''''FEHLER''''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets("Länderansicht").Select
Worksheets("Länderansicht").Activate
Worksheets(test).Delete
Marke:
Application.DisplayAlerts = True


Tanks a lot,
Michael



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default error runtime 9: deleting a worksheet

I don't really understand why I get an error when I try to delete a
worksheet
that does not exist. That's the reason I put the "on error" statement
around the code. Is it possible to test whether the worksheet "test"
exists
or not?

Thanks,
Michael

"Tom Ogilvy" wrote in message ...
You would get this error if test does not match the name of a sheet in the
activeworkbook. (could be a spelling error or a matter of extra spaces or
example)

--
Regards,
Tom Ogilvy


wrote in message
om...
Hello,
I wrote following code and sometimes I get an runtime error 9. I don't
really know when and why this error occurs. The value of test is never
empty.


On Error GoTo Marke
Application.DisplayAlerts = False
test = Worksheets("Länderansicht").Range("A" & i).Value
''''''''FEHLER'''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets(test).Select ''''''''''HIER TRITT DER FEHLER AUF
'''''''FEHLER''''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets("Länderansicht").Select
Worksheets("Länderansicht").Activate
Worksheets(test).Delete
Marke:
Application.DisplayAlerts = True


Tanks a lot,
Michael

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default error runtime 9: deleting a worksheet

Normally you wouldn't since you have an error handler. I suspect this is
in a loop and you never get out of error handling mode after you encounter
the first sheet that doesn't exist - so you get the error the second time
you encounter a sheet that does not exist -- an error in error handling mode
halts execution.

Try this:

On Error GoTo Marke
Application.DisplayAlerts = False
test = Worksheets("Länderansicht").Range("A" & i).Value
''''''''FEHLER'''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets(test).Select ''''''''''HIER TRITT DER FEHLER AUF
'''''''FEHLER''''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets("Länderansicht").Select
Worksheets("Länderansicht").Activate
Worksheets(test).Delete
Marke:
Resume NextMarke
NextMarke:
Application.DisplayAlerts = True

--
Regards,
Tom Ogilvy


wrote in message
m...
I don't really understand why I get an error when I try to delete a
worksheet
that does not exist. That's the reason I put the "on error" statement
around the code. Is it possible to test whether the worksheet "test"
exists
or not?

Thanks,
Michael

"Tom Ogilvy" wrote in message

...
You would get this error if test does not match the name of a sheet in

the
activeworkbook. (could be a spelling error or a matter of extra spaces

or
example)

--
Regards,
Tom Ogilvy


wrote in message
om...
Hello,
I wrote following code and sometimes I get an runtime error 9. I don't
really know when and why this error occurs. The value of test is never
empty.


On Error GoTo Marke
Application.DisplayAlerts = False
test = Worksheets("Länderansicht").Range("A" & i).Value
''''''''FEHLER'''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets(test).Select ''''''''''HIER TRITT DER FEHLER AUF
'''''''FEHLER''''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets("Länderansicht").Select
Worksheets("Länderansicht").Activate
Worksheets(test).Delete
Marke:
Application.DisplayAlerts = True


Tanks a lot,
Michael



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default error runtime 9: deleting a worksheet

That's right! I always get the error the second time a worksheet doesn't
exist. Is there any possibility to get out of this error mode?

Thanks,
Michael

"Tom Ogilvy" wrote in message ...
Normally you wouldn't since you have an error handler. I suspect this is
in a loop and you never get out of error handling mode after you encounter
the first sheet that doesn't exist - so you get the error the second time
you encounter a sheet that does not exist -- an error in error handling mode
halts execution.

Try this:

On Error GoTo Marke
Application.DisplayAlerts = False
test = Worksheets("Länderansicht").Range("A" & i).Value
''''''''FEHLER'''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets(test).Select ''''''''''HIER TRITT DER FEHLER AUF
'''''''FEHLER''''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets("Länderansicht").Select
Worksheets("Länderansicht").Activate
Worksheets(test).Delete
Marke:
Resume NextMarke
NextMarke:
Application.DisplayAlerts = True

--
Regards,
Tom Ogilvy


wrote in message
m...
I don't really understand why I get an error when I try to delete a
worksheet
that does not exist. That's the reason I put the "on error" statement
around the code. Is it possible to test whether the worksheet "test"
exists
or not?

Thanks,
Michael

"Tom Ogilvy" wrote in message

...
You would get this error if test does not match the name of a sheet in

the
activeworkbook. (could be a spelling error or a matter of extra spaces

or
example)

--
Regards,
Tom Ogilvy


wrote in message
om...
Hello,
I wrote following code and sometimes I get an runtime error 9. I don't
really know when and why this error occurs. The value of test is never
empty.


On Error GoTo Marke
Application.DisplayAlerts = False
test = Worksheets("Länderansicht").Range("A" & i).Value
''''''''FEHLER'''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets(test).Select ''''''''''HIER TRITT DER FEHLER AUF
'''''''FEHLER''''''''''''''''''''''''''''''''''''' ''''''''''''''
Worksheets("Länderansicht").Select
Worksheets("Länderansicht").Activate
Worksheets(test).Delete
Marke:
Application.DisplayAlerts = True


Tanks a lot,
Michael

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
Macro runtime 1004 error on opening worksheet Shaggyjh Excel Discussion (Misc queries) 5 May 6th 09 12:37 PM
Set worksheet range runtime error 1004 DaveP Excel Programming 1 March 29th 05 07:13 AM
Validation.Modify Runtime Error in Protected Worksheet Kent Klingler Excel Programming 3 May 13th 04 09:18 PM
RUNTIME ERROR '1004' --- Select method of worksheet class failed jawee Excel Programming 2 April 30th 04 06:47 AM


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