+ Reply to Thread
Results 1 to 4 of 4

Error not being trapped?

  1. #1
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Error not being trapped?

    Hi I am trying to make sure that I give my worksheet a unique name in the workbook. To do this I create a name that really really really should be unique, but just in case I also try to check it against existing worksheets, and this is where I am having the problem. I thought the following code would trigger the 'goto' on a 'subscript out of range' error (ie. the sheet doesn't exist), and then carry on:

    Please Login or Register  to view this content.
    However for some reason I am STILL getting the "Run-time error '9' Subscript out of range" box popping up when the code hits the line where I try to assign to temp_str.
    I KNOW that the subscript SHOULD be out of range, but my error handler doesn't seem to be error handling very well...

    Any ideas?

    Thanks!

    [EDIT] I should mention that this code is inside a 'For' loop, so will be repeated over and over if that makes a difference.
    Last edited by Phil_V; 10-03-2008 at 06:32 AM. Reason: Bootnote

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I use this User Defined Function to check a worksheet name

    Please Login or Register  to view this content.
    Then something like

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770
    Cheers, looks a lot tidier, I think I'll do something like that
    Out of curiosity any idea why the first one doesn't capture the error?
    Looking at it further it seems to capture it, and follow the goto correctly on the first pass through the loop, but on the second time through the loop it brings up the erro dialogue.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Not really sure without knowing exactly what you are doing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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