+ Reply to Thread
Results 1 to 5 of 5

Macro not working

  1. #1
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Macro not working

    Can someone debug this code for me. I can't figure out why it isn't working.
    Please Login or Register  to view this content.
    Here is the goal of the code:

    Check for a Worksheet with the name found in NamedRange "SheetName".
    If Worksheet NOT found...then Create Worksheet named "SheetName".
    If Worksheet FOUND...then MsgBox outlining User Options.

    Option 1: DELETE old Worksheet and Create NEW Worksheet named "SheetName".
    Option 2: GO TO old worksheet.


    Option 2 works perfectly.
    Option 1 results in Run-time error '13': Type mismatch
    The error occurs on the following line:
    Please Login or Register  to view this content.

    I read online that sometimes...a copy/paste of VBA will cause this error.
    So I deleted the line of code that was flagged...and typed it manually.
    Obviously...that didn't work, or you wouldn't be reading this.
    (It DID work, however, on another section of the code that was producing the same error).

    Have I coded something wrong?? Or...is there some other problem??

    Attached...is a sample Workbook...for examination.
    Attached Files Attached Files
    Last edited by HuskerBronco; 09-19-2010 at 09:07 AM. Reason: Mark SOLVED

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Macro not working

    I just loaded the sheetname value in to a variable to avoid all the issues.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Macro not working

    Of course, Andy...

    I knew I was leaving out something simple.

    I based that code on an example online.
    The author of the original code also failed to assign the "SheetName" value to a variable.

    Everything works as expected, now. Thanks...!!!

  4. #4
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro not working

    hi,

    After typing up this post, I realised the thread is already marked as Solved, but since I've done the typing I thought I would post it anyway...

    Here's a short function that uses the same principles for identifying if a sheet exists, but it is more portable because it's "wrapped" into a function.

    Please Login or Register  to view this content.
    This would allow you to test for the existence of the sheet with the same name before attempting to name (or even, before creating) the new sheet, for example:

    Please Login or Register  to view this content.

    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  5. #5
    Forum Contributor
    Join Date
    01-12-2004
    Location
    Nebraska, USA
    MS-Off Ver
    Office 365
    Posts
    167

    Re: Macro not working

    Rob...

    Thanks for responding to my thread.

    Yes, my thread had already been marked "Solved" when you posted...
    But...I'm glad you posted anyway. Your solution involves use of a UDF,
    which is something I have not dabbled in, yet. It is something I
    certainly want to explore...since I think it will allow me to construct
    more versatile and efficient VBA code.

    Your code is especially useful, since it can be used in ALL of my projects
    that require worksheet detection.

    Thanks, again....

+ 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