+ Reply to Thread
Results 1 to 5 of 5

Error Handling

  1. #1
    Registered User
    Join Date
    05-24-2016
    Location
    Singapore
    MS-Off Ver
    Excel
    Posts
    4

    Question Error Handling

    I am trying to create a code that deletes a worksheet named "Optimisation" if it exists and create a new one under the same name, or simply create "Optimisation" if it doesn't exist.

    I am aware that this will raise an error if the sheet "Optimization" does not exist. I followed the error tackling methods found at this site, however I am still unable to proceed after the second line which raises the error "run-time error: subscript out of range".

    I am also trying to avoid the "run-time error: automation error", which comes up at random times while running my code. (I have read somewhere that this arises when multiple worksheets are open simultaneously, however I am only referring to one existing worksheet and the newly created "Optimisation" worksheet so I don't understand why I am getting this)

    This is at the very top of my code (no other error handlers active on top of this part of the code):
    Please Login or Register  to view this content.
    Could someone please tell me why this is happening and how I will be able to fix this? Thank you.

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Error Handling

    move negation in front of testing "whether object is nothing"
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Error Handling

    BTW: Before adding new sheet, I'd recommend to restore strict error handling with
    Please Login or Register  to view this content.

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,903

    Re: Error Handling

    If you are seeing an error when you have an On Error Resume Next in operation, your VB Editor has been set to break on all errors. Change that under Tools- Options, General tab, to either Break on unhandled errors, or Break in Class module.

    BTW, you don't really benefit from using a variable here - you can just do:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-24-2016
    Location
    Singapore
    MS-Off Ver
    Excel
    Posts
    4

    Re: Error Handling

    Thank you Kaper and Rorya for your suggestions, I have tried them and am glad to see that they effectively countered the error I had at hand!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Error handling inside error handling
    By grantastley in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-06-2015, 03:43 AM
  2. RUN TIME ERROR '1004' error handling help needed
    By skop89 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-09-2014, 12:54 PM
  3. [SOLVED] Error Handling: Creating code to display error messages
    By Student1990 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-01-2013, 02:21 PM
  4. Error Handling: Can it report line # where error occurred?
    By PingPing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2010, 03:47 AM
  5. On Error Goto (Global Error Handling)
    By mpeplow in forum Excel General
    Replies: 3
    Last Post: 04-10-2007, 11:33 PM
  6. Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM
  7. [SOLVED] Error handling with a handling routine
    By ben in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1