+ Reply to Thread
Results 1 to 5 of 5

if sheet name exists then exit sub - error

  1. #1
    Registered User
    Join Date
    08-16-2013
    Location
    Houston, US
    MS-Off Ver
    Excel 2007
    Posts
    22

    if sheet name exists then exit sub - error

    Hello,

    I have this code then works when it enters the if statement but when the condition is not satisfied then it returns runtime error 9, subscript out of range. Why does it work when the condition is satisfied and not when it doesn't?

    Please Login or Register  to view this content.
    Trial name is a string and when the condition is satisfied then the messgage box apeared.

    Thank you very much for the help. Have a nice day.

    -Rob

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: if sheet name exists then exit sub - error

    & is forbidden chr in naming names

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: if sheet name exists then exit sub - error

    Hello CobertRannon,

    Error 9 indicates that a variable, in your case one you have used for the worksheet or a range on the worksheet, has not been assigned yet. It would be helpful to see the full macro code.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: if sheet name exists then exit sub - error

    It's might be going into error because a sheet doesn't exist with that name which leads to a bigger question. Why on earth are you asking if an existing sheets name, has a name, which is it's name? Of course it is it's name.

    It would be like going up to my friend Bob and saying; "Bob, if your name is Bob can you please pass me a beer".

    If you are just trying to see if a sheet name exists there are other ways around it. Here is an example;

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-16-2013
    Location
    Houston, US
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: if sheet name exists then exit sub - error

    That worked great. Your analogy was perfect.

    Thank you so much for your time. Have a nice day.

    -Rob

+ 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. VBA error during execution at Exit Sub
    By sportsguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2013, 01:32 PM
  2. [SOLVED] Check if sheet exists and delete it using IF ERROR function in VBA
    By Jardim in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-25-2012, 12:06 PM
  3. IF Error Then Exit Macro Help!
    By pmorris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2007, 05:05 AM
  4. simplest VBA code to exit a sub using On Error?
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-16-2007, 06:46 PM
  5. on error exit sub
    By short_n_curly in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-20-2005, 02:01 PM

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