+ Reply to Thread
Results 1 to 5 of 5

UDF returning #VALUE when another Excel file is opened

  1. #1
    Registered User
    Join Date
    06-04-2013
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    2

    UDF returning #VALUE when another Excel file is opened

    Hi. I'm new to the world of Excel programming, so I hope I'm not being too simple here. I've Googled around for the answer to this and couldn't find a simple fix.

    I've created some UDFs for a specific Excel file I'm working on. Here's the code:

    Please Login or Register  to view this content.
    When I open my file, everything works fine, and the cells using those UDFs update as they should. When I open another Excel file, though, the cells using the ExtraQuantity function return #VALUE, and I have to double-click on the cells and press ENTER to get them to calculate correctly again. I can save at this point and reopen and everything's fine, but it errors again as soon as I open another file. What should I add to my functions to keep this from happening? Thanks.

  2. #2
    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
    48,203

    Re: UDF returning #VALUE when another Excel file is opened

    How are you calling the functions? Might be useful to upload a sample workbook with some typical data.

    Regards, TMS
    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


  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: UDF returning #VALUE when another Excel file is opened

    I suggest you pass the extrapercentage value to the function as an argument rather than relying on a named range in the code
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Registered User
    Join Date
    06-04-2013
    Location
    Kansas City, MO
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: UDF returning #VALUE when another Excel file is opened

    JosephP, that seems to have fixed it! Any insight as to why using a named range was causing a problem? (I assume it's to do with the newly opened file not having that named range, but it seems odd that Excel would get hung up by that.)

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: UDF returning #VALUE when another Excel file is opened

    your code doesn't specify where the named range is so it defaults to looking in the active workbook. it's better to pass the value as an argument-then your function doesn't need to be volatile any more

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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