+ Reply to Thread
Results 1 to 9 of 9

Strange phenomena when use function

  1. #1
    Registered User
    Join Date
    09-13-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Question Strange phenomena when use function

    Hi, there
    I developed a function to return a string. However, if I return the function value after the line below, it always comes out as “#Value!” in the location I am calling it. Any suggestions?


    Please Login or Register  to view this content.

    Thanks in advance.

    Regards,
    Lily
    Last edited by SpringLily; 01-10-2012 at 11:16 AM. Reason: Solved

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

    Re: Strange phenomena when use function

    If you are trying to use that function from the worksheet it will fail as you have code to activate the cell containing searched for text, which is not allowed from sheet functions.

    How exactly are you using that function?
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    09-13-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Strange phenomena when use function

    Hi, Andy
    I used the function by the equation below for a cell:

    =IF(INSomething<>"",INSomething,FindString)

    where InSomething is a defined name and FindString is the function for finding the right information. The code for the function is listed above.

    Thanks.
    Regards,
    Lily

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

    Re: Strange phenomena when use function

    As I said functions called from worksheets do not allow alteration or selection of other cells.

    Apart from that in your function was does LatNow refer to?
    What would the selection be referring to?
    Why a udf function rather than using VLOOKUP or MATCH?

  5. #5
    Registered User
    Join Date
    09-13-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Strange phenomena when use function

    The code itself is rather long (>100 sentences). I only quoted the line which caused problem. LatNow is defined before the line. Shall I use a sub instead of a function?

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

    Re: Strange phenomena when use function

    If you are using from a cell it will need to be a function in order to return a value to the cell.

    You can use the find function but not the .Activate part.

  7. #7
    Registered User
    Join Date
    09-13-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Strange phenomena when use function

    The reason for me to use .activate part it to get the row number of the searched results. Below are the two lines from my function.

    Please Login or Register  to view this content.
    how do I modify the code to make it work?

    Thanks.

    Regards,
    Lily

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

    Re: Strange phenomena when use function

    Please Login or Register  to view this content.
    Note the Selection and Activecell references will also need to change in order for the code to work properly from worksheet.

  9. #9
    Registered User
    Join Date
    09-13-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: Strange phenomena when use function

    Thanks. It works! Regards, Lily

+ 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