+ Reply to Thread
Results 1 to 6 of 6

Odd Error Handling Behaviour; goes to error handler even when no error?

  1. #1
    Registered User
    Join Date
    08-15-2014
    Location
    Winchester, England
    MS-Off Ver
    2007
    Posts
    3

    Odd Error Handling Behaviour; goes to error handler even when no error?

    I am using a macro that creates a new worksheet, and copies the existing visible worksheet range into that new worksheet; the code then asks the user to rename the new worksheet. I have an error handling procedure that should be activated only when there is an error; i.e. when the user tries to give a new / copied sheet the same name as an existing one. However when I execute the code, it goes into the error handling procedure even when there is no error, necessitating the naming of a worksheet twice in order for the code to complete! I have been banging my head against a brick wall and just cannot see what I am doing wrong! Please can you help.

    Code as follows:

    Please Login or Register  to view this content.
    Thank you in advance,

    Best regards,

    Jason

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Odd Error Handling Behaviour; goes to error handler even when no error?

    You've forgotten the

    Please Login or Register  to view this content.
    Immediately before the ErrHandler line
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,007

    Re: Odd Error Handling Behaviour; goes to error handler even when no error?

    RB beat me to the solution to the stated problem. However, if there is a genuine error, there's not much point using an InputBox to ask for an alternative as you just drop out of the bottom of the macro anyway. You really need a mechanism for looping back, maybe x times (x = 2, 3, 4, whatever).
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    08-15-2014
    Location
    Winchester, England
    MS-Off Ver
    2007
    Posts
    3

    Re: Odd Error Handling Behaviour; goes to error handler even when no error?

    Richard, Thank you, DOH! It seems to be that the simplest errors are sometimes the hardest to spot! One of Confucius's many laws methinks! Thank you once again, problem solved.

  5. #5
    Registered User
    Join Date
    08-15-2014
    Location
    Winchester, England
    MS-Off Ver
    2007
    Posts
    3

    Re: Odd Error Handling Behaviour; goes to error handler even when no error?

    Thank you for your input also TMS, I will take your point on board.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,007

    Re: Odd Error Handling Behaviour; goes to error handler even when no error?

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ 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 Handler for Compile Error in Hidden Module
    By Jerbinator in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-29-2016, 01:56 PM
  2. 'While' function inside of error handler giving an error/failing
    By dnwadams in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2015, 12:18 AM
  3. [SOLVED] Need error handler code to avoid pivot table refreshing error if no data is available
    By adelkam in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-04-2015, 12:37 PM
  4. [SOLVED] Error handler while handling an error... How do we do that?
    By r2fro in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2014, 11:28 AM
  5. [SOLVED] Error Handling strange behaviour, it only works the first time
    By Henk Stander in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-08-2012, 10:10 AM
  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] Form Err.Raise error not trapped by entry procedure error handler
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2006, 06:25 AM

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