Need to find time difference between most recent time listed in a column

knoharra

New Member
Joined
Dec 6, 2024
Messages
11
Office Version
  1. 365
Platform
  1. Windows
I am trying to calculate the time difference between 2 cells in time column A, but only if the time slot cell in Column B is used. See screenshot below of Columns A&B, assuming the top left is cell A1. For example, B4 (13:30) correctly shows 13h and 30 min between cells a4 & a3 times. However, in cell b11 (1:00) I want to calculate 4:00 (4h between 12pm in a11 and 8am in a4). How can I do this? Currently I am just using an if function referring to another cell to return a value or "-". If needed I am ok with changing the "-" to "#N/A" and I am able to do this, I just thought the "-" was cleaner looking. Thank you.
 

Attachments

  • Screenshot 2024-12-06 144044.png
    Screenshot 2024-12-06 144044.png
    5.6 KB · Views: 18

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
If your dates are formatted as dates and the B column is formatted as Time then there shouldn't be an issue except
but only if the time slot cell in Column B is used
you can't have data entered as a value and also a formula in the same cell. Besides, every row in colB that you show is used - you have dashes in there.
 
Upvote 0
It works if I manually select each cell, but I'm hoping to use something that says to only calculate the difference in column a rows if there is a non " - " value in a cell reference outside of my screenshot (eg C1).
 
Upvote 0
try this using your cell references
=IF(Y2<>"-",W3-W2,"")

I used W for your A column and Y for your C column
 
Upvote 0
try this using your cell references
=IF(Y2<>"-",W3-W2,"")

I used W for your A column and Y for your C column
I'm probably not explaining well. This is similar to what I have, but it always calculates the difference in the most recent previous time. If the most recent time is not used, instead of w3-w2, I instead want to calculate for example w3-w1.

For clarity, imagine game time slots a,b,& c on a field. Field 1 has a game during time slots a&c but field 2 in another column has games during time slots b&c. I want a common formula that gives time c-a for Field 1 but c-b for Field 2. Another section of my worksheet tells excel if there is a game during the time slots in column a. Does this make more sense?
 
Upvote 0
I'm probably not explaining well
No argument there. I suggest you try posting sample data as well as expected results. xl2BB is the best method; copy/paste from sheet not as good but is still better than pics. With pics you force people to type out data to try things, and some won't, so you lose potential participants.
 
Upvote 0
Welcome to the MrExcel board!

As suggested by @Micron please consider XL2BB for your sample data to make it easier for people to help you.
(If you have trouble with XL2BB, review the "XL2BB Icons greyed out" link in the 'Known XL2BB issues' section near the top of the XL2BB Instructions page linked above.)

See if this is the sort of thing you are after.

24 12 07.xlsm
ABC
1Date/TimeTime DiffRef
212/09/2025 6:00 PM--
312/09/2025 6:15 PM--
412/09/2025 6:30 PM0:15
513/09/2025 8:00 AM13:30
613/09/2025 8:15 AM--
713/09/2025 9:00 AM--
813/09/2025 9:30 AM--
913/09/2025 10:00 AM--
1013/09/2025 10:45 AM--
1113/09/2025 11:00 AM--
1213/09/2025 12:00 PM4:00
1313/09/2025 1:00 PM--
Time Diff
Cell Formulas
RangeFormula
B2:B13B2=IF(C2="-",C2,A2-IFNA(LOOKUP(9^9,B$1:B1,A$1:A1),A1))
 
Upvote 0
Thanks guys. The IFNA & lookup function works as intended. In the future I'll try to include an XL2BB file.
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 0
Ok so I'm realizing this isn't always working as intended. I've attached some minisheets to help. I have made a sports tournament master schedule (1st minisheet, a range rather than table since the times and fields are an array that could change each tournament). Games are identified as anything that begins with U*, and anything with "1st", "2nd", "5th", or "Div" in the white cells is a Championship Game with longer time needed between games, while any game without this is preliminary. FYI I'm currently using "0" in this chart as I was trying to find a way using non-zero numbers, but ideally I'd like to keep non-games as "-" if possible.

My goal is to ensure adequate time between games. I'm doing this in the 2nd minisheet where fields/times replicate those in the 1st. In B54, ideally I'd like it to state "First Game" since there are no prior games on Field 1, but not required. I do need A55 and all cells under this in column A to give me the times between games. So B57 should give h:mm as 14:00 for 14 hours between A57 & A54. Currently it's giving 13:30 since only goes back to previous time slot which would work if I'm only dealing with 1 field, but I'm dealing with several. B58 calculates ok since previous game is previous time slot, and B60 is ok I don't understand formula well enough to understand why. But in column C (Field 2) I'd like to copy formula over so that C56 says "First Game", C57 gives 13:30, and C59 gives 24:00.

Once all correct, I'd like a conditional formatting formula that will highlight red anything that is less than the minimum time between games, referenced using the "Field" table in a sheet called "Fields", segregating times based on whether it's preliminary or final/championship game as outlined in my 1st paragraph and times referenced in the "Field" table. FYI I removed my conditional formatting I had temporarily to highlight the cells that aren't doing what I wanted.

Thanks for any help you can offer.

Schedule Makeup New.xlsm
ABC
1Time/FieldField 1Field 2
29/12/25 6:00 PMU08 Boys Blue, A vs C0
39/12/25 6:15 PM00
49/12/25 6:30 PM0U08 Boys Blue, B vs D
59/13/25 8:00 AMU08 Boys Blue, D vs AU08 Boys Blue, B vs C
69/13/25 11:00 AMU08 Boys Blue, A vs B0
79/14/25 8:00 AM0U08 Boys Blue, C vs D
89/14/25 10:00 AMU08 Boys Blue, 1st vs 2nd0
MasterChart
Cell Formulas
RangeFormula
B1:W1B1=TRANSPOSE(Field[Field])
A2:A8A2=SORT(Time[Combined])
B2:C8B2=IFERROR(TEXTJOIN({", "," vs "},TRUE,CHOOSECOLS(FILTER(MasterSchedule!$A$6:$E$505,(MasterSchedule!$D$6:$D$505=B$1)*(MasterSchedule!$E$6:$E$505=$A2)),1,2,3)),0)
Dynamic array formulas.



Cell Formulas
RangeFormula
A53A53=A1
B53:C53,A54:A60B53=IF(ISBLANK(B1),"",B1)
B54:C60B54=IF(B2=0,"-",$A2-IFERROR(LOOKUP(9^9,B$53:B53,$A$53:$A53),$A53))
Named Ranges
NameRefers ToCells
_FilterDatabase=MasterChart!$A$1:$W$50A53


Schedule Makeup New.xlsm
ABCD
1FieldSizeMinBetween (Prelim)MinBetween (Final)
2Field 17v76575
3Field 211v117595
Fields
Cell Formulas
RangeFormula
C2:C3C2=IFS(OR(B2="7v7",B2="9v9"),65,B2="11v11",75)
D2:D3D2=IFS(B2="7v7",75,B2="9v9",85,B2="11v11",95)
Cells with Data Validation
CellAllowCriteria
B2:B3List7v7,9v9,11v11
 
Upvote 0

Forum statistics

Threads
1,225,397
Messages
6,184,716
Members
453,254
Latest member
topeb

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top