+ Reply to Thread
Results 1 to 8 of 8

User defined function returning #VALUE!

  1. #1
    Registered User
    Join Date
    10-21-2007
    Posts
    6

    User defined function returning #VALUE!

    This is in excel 2002

    I created my own function that looks up values from other closed workbooks and sums them. The part that looks up the values from the other workbooks, gets the correct value... but in my active worksheet the cell value displays as #VALUE!

    not sure what the problem is. any help is much appreciated!

    this is a simplified version of the user defined function:

    Please Login or Register  to view this content.

    This is the function that actually looks up the value... got this online:

    Please Login or Register  to view this content.
    Last edited by rabson; 10-21-2007 at 06:36 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    If the function is in another workbook then you will have to ref that workbook

    e.g if in book1 it would look like

    =Book1!GetCellValue(
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    10-21-2007
    Posts
    6
    It's actually calling SumOverWorkbooks, not GetCellValue. GetCellValue is just a helper function used by the SumOverWorkbooks function. Yes, I am using the function in the same workbook as where it's defined. From there is goes through a bunch of other files to sum up values and display the result in the cell.

    Please Login or Register  to view this content.
    Thanks for the reply

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598
    A couple of thoughts/questions:
    SumOverWorkbooks()
    • You have dim'd lTotal as Integer but the "L" indicates long, how big are the numbers you are expecting?
    • You say that lTotal is in a loop; but, as written, the current value will be replaced by the new value. Should you have:
      lTotal =lTotal + GetCellValue...
    • You have defined lTotal as Integer but, you are using CInt to convert the value to Integer(?)
    Function GetCellValue(...
    • If your file does not exist, the Fn returns a "...not found" string; but, SumOverWorkbooks() will try to assign the string to the integer variable iTotal
    Finally, you are using CInt in several places. Do you know of a certainty that the values will ALWAYS be numeric? CInt will return #Value if not. Can you add code to test for numeric/non-numeric?
    Ben Van Johnson

  5. #5
    Registered User
    Join Date
    10-21-2007
    Posts
    6

    Wink

    Thanks for your reply. Sorry about the looks of the code... i keep changing it around trying to get it to work. the "l" was for "local"... but i'm a java developer and that's my companies normal standards

    for now i'm sure the values are always numbers. in the simple case i'm trying to get working let's assume that we're dealing with 1 file, 1 cell, and you know there's a number there. I thought it had to do with using the ExecuteExcel4Macro command so i tried a different method below but still no go! i had a msg point right before the end of the function and i KNOW that it has no problem getting the value from the other workbook... it just doesn't get displayed properly in the cell. "#VALUE!"

    I also thought it might have had something to do with the datatype of the return value so that's when i started converting the value to an integer.

    any help would be much much appreciated! maybe you can try creating 2 workbooks and pasting this code into a function. call the file 1.xls and see if it works.

    thanks

    Please Login or Register  to view this content.
    Last edited by rabson; 10-22-2007 at 07:26 AM.

  6. #6
    Registered User
    Join Date
    10-21-2007
    Posts
    6
    Actually, I've attached a test sample with 2 workbooks if you could please have a look. Open the test.xls and in cell A1 you'll see the call to the function. That should be looking in 1.xls for the value in it's A1 cell and displaying it in test.xls.

    Thanks so much!
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-21-2007
    Posts
    6
    bump. have been trying for hours but still no go. i'm about to offer money for a solution!

  8. #8
    Registered User
    Join Date
    10-21-2007
    Posts
    6

    Thumbs up

    ok... so it turns out that this type of functionality can NOT be called from a worksheet cell. not sure why, but you have to put it into an even macro.

    http://www.mcgimpsey.com/macoffice/e...cellvalue.html

    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