+ Reply to Thread
Results 1 to 5 of 5

Function not running correctly (keep getting #VALUE error)

  1. #1
    Registered User
    Join Date
    08-24-2010
    Location
    Lausanne, Swizerland
    MS-Off Ver
    Excel 2007
    Posts
    3

    Function not running correctly (keep getting #VALUE error)

    I am writing a very simple function to calculate pressure drop along a rough pipe, the code is below

    Please Login or Register  to view this content.
    From my understand of the way I've written the function, I should be able to execute it by simply writing =pdrop() into any cell in my worksheet.. this is not the case however. If I do this I simply get a #VALUE error, and I know the input data I'm using works because I've tested it independently elsewhere. Any ideas as to what could be the problem?

    NB: This is the first function I've had to write so if I've done anything stupid don't hesistate to let me know as I need to pick VBA up quite quickly.

  2. #2
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Function not running correctly (keep getting #VALUE error)

    Probably better written like so,

    Please Login or Register  to view this content.
    and used like this:

    Please Login or Register  to view this content.
    Rule 1: Never merge cells
    Rule 2: See rule 1

    "Tomorrow I'm going to be famous. All I need is a tennis racket and a hat".

  3. #3
    Registered User
    Join Date
    08-24-2010
    Location
    Lausanne, Swizerland
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Function not running correctly (keep getting #VALUE error)

    Thank you sweep that worked perfectly. With regards to assigning cell values to the variables what was the problem? Was it because I listed the variables in the function both as inputs AND as separate variables within the code? (I take it this was the wrong thing to do).

    Thanks again.

  4. #4
    Forum Expert sweep's Avatar
    Join Date
    04-03-2007
    Location
    Great Sankey, Warrington, UK
    MS-Off Ver
    2003 / 2007 / 2010 / 2016 / 365
    Posts
    3,444

    Re: Function not running correctly (keep getting #VALUE error)

    The error was being raised because there were insufficient arguments in the function call, in much the same way as if you entered =SUM() into a cell. You could (although it's foolish to do so) enter something along the lines of =pdrop(1,2,3,4,5) into a cell, which will pass the correct number of arguments to the function code, which will immediately overwrite those values with the contents of the cells (specified in your original code).

    To use specific cells as the arguments in your function, your opening line should have been

    Please Login or Register  to view this content.
    followed by dimensioning of variables, and assigning values.


    For my money, if you're writing a function, you're almost certainly at some time going to want to change the cells that contain its arguments, so I would stick with my interpretation of your code.

    I hope that's clear - let me know if not.

  5. #5
    Registered User
    Join Date
    08-24-2010
    Location
    Lausanne, Swizerland
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Function not running correctly (keep getting #VALUE error)

    No that makes perfect sense, I agree that your way makes the function more versatile. Many thanks!

+ 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