+ Reply to Thread
Results 1 to 11 of 11

Vlookup problem when looking for a calulated time difference

  1. #1
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Vlookup problem when looking for a calulated time difference

    Hi all,

    I have run into a little problem that i hope you can help me with. In my attached workbook there are two sheets, "Time" and "Reference". In "Time" i have my data; col A is start time, col B is stop time col C is the difference between them, and in col D is the vlookup that refers to sheet "Reference". I want to find each difference in col C and take the correct value from sheet "Reference". I get an error. Can somebody help me explain why and how i can solve my problem?

    /Masun
    Attached Files Attached Files

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Vlookup problem when looking for a calulated time difference

    Try this

    =VLOOKUP(C2,Reference!A1:$B$6169,2,1)
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Vlookup problem when looking for a calulated time difference

    Hi,

    Thank you for quick replay! Why dont i get a hit when i want to use exakt match?

    /Masun

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Vlookup problem when looking for a calulated time difference

    Also, forgot to change the A1 in your formula should be $A$1 then you should get all matches.

  5. #5
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Vlookup problem when looking for a calulated time difference

    Hi,

    Yeah i changed that. But howcome it dosent work with an exact match? Any ideas?

  6. #6
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Vlookup problem when looking for a calulated time difference

    The exact match can happen when values are exactly the same

    7:11 on the Time sheet is actually 0.299305555556202

    7:11 on Reference sheet is 0.299305555555556

    Please don't forget to thank those who helped by clicking on Add Reputation * and please mark thread as "Solved" if your issue has been resolved. (Selecting Thread Tools-> Mark thread as Solved).

  7. #7
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Vlookup problem when looking for a calulated time difference

    Hi,

    But how can the values be different? Donīt understand that. I calculated one of them and its just a matter of hours and minutes, the other i just autofilled manually, how can there be different values? 7 hours and 11 minutes would be the same value regardless if its calculated or manually added?

  8. #8
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Vlookup problem when looking for a calulated time difference

    Times are stored internally by Excel as fractions of a 24-hour day, so 12 noon has the value 0.5, 6:00am is 0.25, 6:00pm is 0.75, and so on. Now, as these are fractional values, they cannot be stored with complete accuracy, as there is a limit to the number of bytes used for storing fractions. It also turns out that some (decimal) fractions cannot be represented in binary (the number type used by computers), in the same way that 1/3 cannot be expressed completely with decimal fractions.

    Consequently, there will be errors introduced when dealing with times. These errors may be very small (fractions of milliseconds), but they will prevent exact matches of data when you expect there to be a match. You can use MROUND to ensure that the lookup value will be a multiple of a minute, e.g. by doing this:

    =VLOOKUP(MROUND(C2,1/24/60),Reference!$A$1:$B$6169,2,0)

    but that will not always find an exact match as the values in column A of the Reference sheet have not similarly been rounded.

    Another way is to convert your times to text. Put this formula in C1 of the Reference sheet:

    =TEXT(A1,"[h]:mm:ss")

    and copy this down to the bottom. Then copy column B into column D. Then you can use this formula in D2 of the Time sheet:

    =VLOOKUP(TEXT(C2,"[h]:mm:ss"),Reference!$C$1:$D$6169,2,FALSE)

    to find the exact matches.

    Hope this helps.

    Pete

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Vlookup problem when looking for a calulated time difference

    Thank you Pete! I was just about to post pretty much the same method LOL. Good thing I checked before hitting reply.

  10. #10
    Forum Contributor
    Join Date
    01-11-2013
    Location
    Sweden
    MS-Off Ver
    MS 365
    Posts
    188

    Re: Vlookup problem when looking for a calulated time difference

    Pete,

    Thanks for your answer! I will try your solution first thing tomorrow. I am sure it will work. Many thanks!

    Thanks for the explanation. I am not familiar with that binary stuff...but for a noob like me it seems like excel should use the same fractional value when storing 7:11, the number of bytes should be the same. But now i know that it doesnt, and i dont think i understand nor need to understand why it is like this. The knowledge of that it will be problems when dealing with time is enough. Once again, thank you!

    /Masun

  11. #11
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,724

    Re: Vlookup problem when looking for a calulated time difference

    You're welcome - thanks for the rep.

    Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 17
    Last Post: 11-15-2012, 06:12 PM
  2. [SOLVED] Problem matching columns and calculating a time difference. For Pros.
    By maradri in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-07-2012, 05:07 AM
  3. [SOLVED] Problem with VLOOKUP using date and time
    By hijinxx in forum Excel General
    Replies: 5
    Last Post: 05-15-2012, 06:06 AM
  4. Replies: 0
    Last Post: 09-30-2010, 11:04 AM
  5. [SOLVED] Vlookup problem with Date Time
    By normajmarsh in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-03-2006, 03:40 PM

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