+ Reply to Thread
Results 1 to 4 of 4

Worksheet function Vlookup and VLOOKUP return different results

  1. #1
    Registered User
    Join Date
    08-08-2010
    Location
    Krakow, Poland
    MS-Off Ver
    Excel 2007
    Posts
    2

    Worksheet function Vlookup and VLOOKUP return different results

    I'm writing a function to normalize a date based on a simple table of review dates. If a date is between review date and the valid date, it should be normalized to the review date.

    Review Date Valid Until
    01-01-1900 14-04-2009
    15-04-2009 14-04-2010
    15-04-2010 31-12-9999

    Following formula in Excel gives correct result '=VLOOKUP(D5,$A$5:$A$7,1,TRUE)' where the D5 contains a date to be normalized and $A$5:$A$7 is the review dates column.

    However when I'm trying to replicate this with a following code in VBA the function:


    Please Login or Register  to view this content.
    ReviewDate returns different results e.g. ReviewDate("15-04-2009")=15-04-2010.
    I suspect some date conversion issue I've already used CDate to conver dates but no success... Attached files contains the code, and a test

    Any idea what goes wrong?
    Cheers
    Artek
    Attached Files Attached Files
    Last edited by zandero; 08-08-2010 at 08:04 AM.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Worksheet function Vlookup and VLOOKUP return different results

    Try this
    Please Login or Register  to view this content.

    Hope this helps, however I don't really see the advantage with the UDF as it stands.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    08-08-2010
    Location
    Krakow, Poland
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Worksheet function Vlookup and VLOOKUP return different results

    Thanks you!
    It works. I need this in another sub where I validate data from an error log theres a lot's other bits to check and correct, and having this one thing normalized via formula is not pracical.

    Cheers!

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Worksheet function Vlookup and VLOOKUP return different results

    No problem

    This might be a little more versatile.
    It allows Range A5:A7 to grow dynamically
    Please Login or Register  to view this content.

    Hope this helps

+ 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