+ Reply to Thread
Results 1 to 26 of 26

How do I subtract time over midnight the previous day from a vlookup result

  1. #1
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    How do I subtract time over midnight the previous day from a vlookup result

    Hi,

    Cell C72 has the time 00:27. I have data from a vlookup table in cell O 72 of 05:30 (this is hours and minutes not time units am/pm).

    I would like to subtract the 05:30 from the time 00:27 and have the result shown in time in cell O 72.

    I can do this for times before midnight using:

    =ABS(VLOOKUP($A72,'Sheet 1'!$A$3:$E$183,5,TRUE)-C72)

    When I use the above and the time I need to subtract from is after midnight I get 05:03 (basically it has only taken 27 minutes off)

    Any help would be appreciated.

  2. #2
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Welcome to the forum.

    You could try this (untested):

    =ABS(MOD(VLOOKUP($A72,'Sheet 1'!$A$3:$E$183,5,TRUE)-C72,1))
    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.

  3. #3
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: How do I subtract time over midnight the previous day from a vlookup result

    .
    00:27 and 05:30 are in the same day ?

    If not, include the date along with the time for each cell.

  4. #4
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Thanks for trying but it returned the same result

  5. #5
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Attach a sample workbook (NOT a picture!) displaying the issue in context. Instructions at the top of the page in the yellow banner. Otherwise it's just guesswork.

  6. #6
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Quote Originally Posted by Logit View Post
    .
    00:27 and 05:30 are in the same day ?

    If not, include the date along with the time for each cell.
    Hi Logit,

    The 00:27 is the end of a job from the previous day which goes past midnight. I need to deduct the result of the Vlookup table (in the case 5 hours and 30 minutes) from 00:27 in the same cell O 72. The answer I need is 18:57.

    Thanks

  7. #7
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Pleae see post #5 - we need to see this in context.

  8. #8
    Registered User
    Join Date
    12-03-2012
    Location
    CHENNAI , INDIA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Hi ,

    All time values are numbers between 0 and .99999 , where 0 is midnight , and .99999 is 23:59:59

    Also , you cannot do time arithmetic which will result in a negative value.

    Thus , when your time values roll over midnight , just add 1 before you take the difference or subtract.

    Thus , when you wish to subtract five and a half hours from 00:27 , you need to add 1 before you carry out the subtraction.

    1 + "00:27:00" - "05:30:00" will give you 18:57.

    Narayan

  9. #9
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Quote Originally Posted by AliGW View Post
    Pleae see post #5 - we need to see this in context.
    I am having trouble sending it lol
    Attached Files Attached Files

  10. #10
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Try this (based on post #8 above):

    =IF(B2<C2,0,1)+ABS(VLOOKUP($A2,'Sheet 1'!$A$3:$E$183,5,TRUE)-C2)

  11. #11
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Quote Originally Posted by NARAYANK991 View Post
    Hi ,

    All time values are numbers between 0 and .99999 , ...
    Hi Narayan,

    Thanks for your response.

    I still cant get it to work.
    Last edited by AliGW; 10-27-2019 at 11:13 AM. Reason: Please don't quote unnecessarily!

  12. #12
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    See post #10.

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

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Try this:

    =C72 - VLOOKUP($A72,'Sheet 1'!$A$3:$E$183,5,TRUE)-C72 + (VLOOKUP($A72,'Sheet 1'!$A$3:$E$183,5,TRUE)>C72)

    Hope this helps.

    Pete

  14. #14
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Quote Originally Posted by AliGW View Post
    Try this (based on post #8 above):

    =IF(B2<C2,0,1)+ABS(VLOOKUP($A2,'Sheet 1'!$A$3:$E$183,5,TRUE)-C2)
    Lol it still doesnt work it says 18:18. it is supposed to be 5 hours and 30 minutes from 12:27am minutes which should = 18:57

  15. #15
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Quote Originally Posted by Pete_UK View Post
    Try this:

    =C72 - VLOOKUP($A72,'Sheet 1'!$A$3:$E$183,5,TRUE)-C72 + (VLOOKUP($A72,'Sheet 1'!$A$3:$E$183,5,TRUE)>C72)

    Hope this helps.

    Pete
    No Sorry Pete, It left me with a static 18:30

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

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Just put:

    =VLOOKUP($A72,'Sheet 1'!$A$3:$E$183,5,TRUE)

    in a nearby empty cell (formatted as time), so you can see what you are actually subtracting from C72.

    Hope this helps.

    Pete

  17. #17
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    It came back with 05:30.
    Last edited by AliGW; 10-27-2019 at 11:32 AM. Reason: Please don't quote unnecessarily!

  18. #18
    Registered User
    Join Date
    12-03-2012
    Location
    CHENNAI , INDIA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Hi ,

    Isn't this what you are supposed to do ?

    =C3 + 1 - VLOOKUP($A3,'Sheet 1'!$A$3:$E$183,5,TRUE)

    This would be the Excel equivalent of five and a half hours before 00:27 , which is the value in C3.

    This correctly gives 18:57.

    If you wish to generalize this , it would be :

    =C2+IF(C2 >= B2,0,1) - VLOOKUP($A2,'Sheet 1'!$A$3:$E$183,5,TRUE)

    Enter the above formula in O2 and copy it down.

    Narayan
    Last edited by NARAYANK991; 10-27-2019 at 11:45 AM.

  19. #19
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Narayan - we need a formula that will cope with the positives as well - yours only caters for the negative.

  20. #20
    Registered User
    Join Date
    12-03-2012
    Location
    CHENNAI , INDIA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Hi ,

    I wanted OP to first confirm that this is correct.

    I have edited my post to cater to the normal , positive values.

    Narayan

  21. #21
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    I think this will do it:

    =C2+IF(VLOOKUP($A2,'Sheet 1'!$A$3:$E$183,5,TRUE)>C2,1,0)-VLOOKUP($A2,'Sheet 1'!$A$3:$E$183,5,TRUE)

  22. #22
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Hi Naryan,

    It worked for the times going just over midnight.

    As I go further into the early hours time just starts ticking up. i.e. 27: 28:

  23. #23
    Registered User
    Join Date
    12-03-2012
    Location
    CHENNAI , INDIA
    MS-Off Ver
    Excel 2007
    Posts
    93

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Hi ,

    If you can post a file which has as much data as possible , it will make it easier to test for all possible situations.

    Otherwise , try the other suggestions and see if they work.

    Narayan

  24. #24
    Registered User
    Join Date
    10-13-2019
    Location
    Kent
    MS-Off Ver
    365
    Posts
    10

    Re: How do I subtract time over midnight the previous day from a vlookup result

    HI AliGW,

    You did it, thank you so much.

    Kind regards

  25. #25
    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,981

    Re: How do I subtract time over midnight the previous day from a vlookup result

    Ah - at last!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

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

    Re: How do I subtract time over midnight the previous day from a vlookup result

    When I put this formula in Cell O3 in the file you uploaded in Post #9:

    =C3-VLOOKUP($A3,'Sheet 1'!$A$3:$E$183,5,TRUE)+(VLOOKUP($A3,'Sheet 1'!$A$3:$E$183,5,TRUE)>C3)

    I get the result of 18:57.

    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. [SOLVED] VLookup to return value for time hh:mm not working past midnight
    By RayRay248 in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 01-25-2021, 06:05 AM
  2. [SOLVED] Want to extract time before and after midnight for a time range that spans midnight
    By schurchill39 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-26-2018, 04:18 PM
  3. [SOLVED] VLOOKUP - skip previous result
    By TomBP in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-19-2017, 05:59 AM
  4. How to VLOOKUP excluding a previous result
    By Marceltcm in forum Excel General
    Replies: 8
    Last Post: 09-14-2016, 01:22 AM
  5. VLOOKUP not working when time goes past midnight.
    By zerocool2311 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-13-2014, 08:15 PM
  6. Subtract time and obtain result in minutes
    By cssst5 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-03-2014, 12:53 PM
  7. add and subtract time and get result in time format
    By sanjay.ksg27 in forum Excel General
    Replies: 4
    Last Post: 12-31-2009, 07:21 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