+ Reply to Thread
Results 1 to 7 of 7

VLookUp and Times

  1. #1
    Registered User
    Join Date
    09-08-2020
    Location
    Tennessee, United States
    MS-Off Ver
    365
    Posts
    1

    VLookUp and Times

    Greetings everyone,

    I am a bit stumped currently and could use some help on why my VLookUp is not working.

    Right now I am working with 2 tables. 1 is a "Times" lookup table that is structured like this:

    TimeValue Time TimeDesc
    0 12:00:00 AM Night
    .000694444 12:00:01 AM Night
    .001388889 12:00:02 AM Night

    So on and so forth

    The other table contains the data I am trying to sort through. It has 50+ columns, but the key column for this purpose is a column titled "IncidentDate" which contains data structured like this:
    IncidentDate
    1/1/22 12:00:00 AM
    3/5/22 1:15:00 PM

    So on and so forth.

    I essentially want the VLookUp to be able to check the IncidentDate value against the Times lookup table and return the "Night" value. Right now I am using this formula:

    Please Login or Register  to view this content.
    This, however, is not returning any results. Analysis shows that I am getting what I would expect from each part of the formula but it will not find the match in the table.

    Anyone have any pointers?

    Thanks!

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,002

    Re: VLookUp and Times

    Can't see what's where.

    A picture is worth 1,000 words. An Excel sheet is worth 1,000 non-editable pictures.

    Please read the yellow banner about sample worksheets, at the top of the screen. Act on its guidelines and post a SMALL sample sheet complete with an explanation and some expected results.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,657

    Re: VLookUp and Times

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: VLookUp and Times

    Hi,
    as questions concerning date and time can sometimes be special, please post a sample sheet ( see yellow banner for how-to).thx+

  5. #5
    Registered User
    Join Date
    06-22-2022
    Location
    India
    MS-Off Ver
    Microsoft office Home and Student 2019
    Posts
    61

    Re: VLookUp and Times

    Try using the formula highlighted in the excel sheet using Time formula to extract Time from Incidentdate instead of Right().
    When using Vlookup from Times table , First column should be the column with the lookup value.
    S]o,we need to select only two columns(Time and TimeDesc).
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    11-22-2014
    Location
    Arizona, USA
    MS-Off Ver
    Office 365
    Posts
    973

    Re: VLookUp and Times

    Hahah beat me to it HariArvi, I was tempted to post "Send sample data" again...because it cracks me up that it was 3 in a row....

    But the answer is to strip the time out of the date field Reference
    Please Login or Register  to view this content.
    updating your vlookup to use that will solve your issue... but samples are always best
    -If you think you are done, Start over - ELeGault

  7. #7
    Valued Forum Contributor
    Join Date
    07-13-2021
    Location
    California, USA
    MS-Off Ver
    2010
    Posts
    513

    Re: VLookUp and Times

    Quote Originally Posted by Suilenroc View Post
    =VLOOKUP(RIGHT(AX2,LEN(AX2)-FIND(".",AX2)+1),Times,3,FALSE)
    I suspect that you have several problems.

    First, presumably AX2 contains date and time.

    Ostensibly, the better way to extract numeric time is MOD(AX2,1).

    However, since you are using a match function (VLOOKUP), it would be prudent to use --TEXT(MOD(AX2,1),"h:m:s") to round to the exact binary approximation of the time.

    The double-negate converts text to numeric time.

    -----

    Second, with that change, you should eliminate the column that you label "Timevalue".

    Instead, the leftmost lookup column should be what you label "Time". I will call that column B.

    However, I suspect that you build the "Time" column by entering 12:00:00 AM into B2, then starting in B3, entering formulas to increment by one second.

    Those formulas should be of the form =--TEXT(B2+"0:0:1","h:m:s"), again to round to the exact binary approximation of the time. Format the result as Custom h:mm:ss AM/PM.

    -----

    Finally, if you simply want to distinguish between "night", "morning" and "afternoon" times of day -- your example is not complete enough for us to know -- instead of populating the "Times" table with 86400 entries (I presume), consider the following simplification.


    Time Desc
    12:00 AM Night
    6:00 AM Morning
    12:00 PM Afternoon
    6:00 PM Night


    If you enter the leftmost times manually, they will be rounded to their exact binary approximation, by definition.

    Then, your lookup formula becomes:

    =VLOOKUP(--TEXT(MOD(AX2,1),"h:m:s"), Times, 2)

    The missing 4th parameter defaults to TRUE to match the row with the largest time on the left that is less than or equal to the lookup time extracted from AX2.

+ 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. Using VLOOKUP Formula Multiple Times
    By shanis in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-03-2019, 07:00 AM
  2. [SOLVED] VLOOKUP formula with the same value multiple times
    By ba13 in forum Excel General
    Replies: 9
    Last Post: 12-05-2016, 02:50 PM
  3. [SOLVED] dates, times, and Vlookup
    By Trebor777 in forum Excel General
    Replies: 6
    Last Post: 10-03-2016, 10:39 AM
  4. Running a VLOOKUP X times
    By Draygor in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-04-2015, 06:55 PM
  5. If a search term can be found 1 time, 2 times 3 times 4 times 5 times
    By excelcandy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 09:57 PM
  6. use ISNA 3 times with 4 vlookup
    By chrisnaburger in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2010, 07:44 AM
  7. Vlookup longest three times
    By Dave69rock in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-05-2008, 11:20 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