+ Reply to Thread
Results 1 to 6 of 6

Why is UDF always returning False?

  1. #1
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Why is UDF always returning False?

    I borrowed the function from shg in this thread to test if a sheet exists but it is always returning false.

    http://www.excelforum.com/excel-prog...et-exists.html

    I am including the entire code. It does a regression analysis on data for a second degree polynomial. In doing so, it creates a worksheet called Regression. So I test first to see if this sheet already exists within the workbook and then ask the user to delete it if it does. I've stepped through the function and the function is always returning False whether Regression exists or not. Thanks in advance.
    Please Login or Register  to view this content.
    Last edited by ChemistB; 11-19-2009 at 12:10 PM. Reason: added original thread
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Why is UDF always returning False?

    You should borrow it all
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Why is UDF always returning False?

    Okay, that works great! I still don't understand why. If it was always giving FALSE before, shouldn't putting a NOT in front of it always give true? How is the code being interpreted? Thanks

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Why is UDF always returning False?

    If the second line errors, as it will if the sheet doesn't exist, then SheetExists is unmodified, and therefore False.

    If the line doesn't error, then the the result of the assignment is True (the sheet ain't nothin', and therefore is sumthin').

    Capiche?

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

    Re: Why is UDF always returning False?

    If the sheet does not exist an error is raised.
    So actually no resulting value is assigned to SheetExists. It defaults to False.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Why is UDF always returning False?

    Capiche! Thanks to both of you.

+ 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