+ Reply to Thread
Results 1 to 9 of 9

VBA Function Returning #VALUE! Error

  1. #1
    Registered User
    Join Date
    05-12-2012
    Location
    England
    MS-Off Ver
    MS Office 2007 Pro Plus
    Posts
    16

    VBA Function Returning #VALUE! Error

    Hi All,

    Could some help me with the below code please?

    If I the following macro, it returns the value as expected (an integer).

    Please Login or Register  to view this content.
    But it I call it within a worksheet, it throws the #VALUE! error.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Please Login or Register  to view this content.
    Thanks
    Gareth

  2. #2
    Registered User
    Join Date
    01-09-2013
    Location
    Vietnam
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: VBA Function Returning #VALUE! Error

    What is BCIS_DB, this is the name range or worksheet name? If it is worksheet name, you have to change from BCIS_DB to [BCIS_DB$]

  3. #3
    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,489

    Re: VBA Function Returning #VALUE! Error

    My understanding has always been that a UDF used as a worksheet function can only return a value, it cannot make changes to the structure or content of other cells. You try to put something in a cell, hence the issue.


    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


  4. #4
    Registered User
    Join Date
    05-12-2012
    Location
    England
    MS-Off Ver
    MS Office 2007 Pro Plus
    Posts
    16

    Re: VBA Function Returning #VALUE! Error

    Thanks for the response guys'!

    Quote Originally Posted by domfootwear View Post
    What is BCIS_DB, this is the name range or worksheet name? If it is worksheet name, you have to change from BCIS_DB to [BCIS_DB$]
    It's a name range.

    Quote Originally Posted by TMShucks View Post
    My understanding has always been that a UDF used as a worksheet function can only return a value, it cannot make changes to the structure or content of other cells. You try to put something in a cell, hence the issue.
    Thanks, I removed it from the function and when using it now in the worksheet, it calculates the amount. The problem is then that it repeats the procedure up until the execute command two or three times for some reason?! Once finished, it then throws the #VALUE! error again?!

    Thanks
    Gareth

  5. #5
    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,489

    Re: VBA Function Returning #VALUE! Error

    Can you post the sample workbook with the code in place. I'd like to step through the code to understand what is happening in relation to the data.

    Two steps forward, one back ... ?

    Regards, TMS

  6. #6
    Registered User
    Join Date
    05-12-2012
    Location
    England
    MS-Off Ver
    MS Office 2007 Pro Plus
    Posts
    16

    Re: VBA Function Returning #VALUE! Error

    Thanks TMS.

    Just to note, removing the part of the VBA that amended the cell certainly appears to have rid the problem. I have a feeling that it's infact something to do with the worksheet_change procedure that's being used throughout the sheet. Should I start a s new question as I don't think it's related now?

    Thanks
    Gareth

  7. #7
    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,489

    Re: VBA Function Returning #VALUE! Error

    OK, if you have a worksheet change event and, in that event handler, you make (more) changes to the worksheet, it will cause the event to fire again, and possibly, again.

    If/where you are making changes, you need:

    Please Login or Register  to view this content.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    05-12-2012
    Location
    England
    MS-Off Ver
    MS Office 2007 Pro Plus
    Posts
    16

    Re: VBA Function Returning #VALUE! Error

    Ok thanks, when I have access to the workbook again, I'll have a go.

    Many thanks
    Gareth

  9. #9
    Registered User
    Join Date
    05-12-2012
    Location
    England
    MS-Off Ver
    MS Office 2007 Pro Plus
    Posts
    16

    Re: VBA Function Returning #VALUE! Error

    Example.xlsm

    Right so I've had a look and it looks like it was trying to call an event whilst enableevents was false. I've attached an example of the workbook, any ideas please as it still doesn't refresh?

    Thanks
    Gareth

+ 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