How to extract Start and End time for a true/false event from a data sheet using vba code?

Syed Ahmad Ali Shah

New Member
Joined
Mar 10, 2023
Messages
8
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I want to extract start and end time into separate columns from a data sheet based on shift timings as shown below;

Shift-1 timing = 06:31-14:30
Shift-2 timing = 14:31-22:30
Shift-3 timing = 22:31-06:30

Requirement:
Start Time (false condition) = ?
End Time (false condition) = ?

DateTimeEventShift
24/02/20236:30TRUE1
24/02/20236:35TRUE1
24/02/20236:40TRUE1
24/02/20236:45TRUE1
24/02/20236:50TRUE1
24/02/20236:55TRUE1
24/02/20237:00FALSE1
24/02/20237:05FALSE1
24/02/20237:10FALSE1
24/02/20237:15FALSE1
24/02/20237:20FALSE1
24/02/20237:25FALSE1
24/02/20237:30FALSE1
24/02/20237:35FALSE1
24/02/20237:40FALSE1
24/02/20237:45TRUE1
24/02/20237:50TRUE1
24/02/20237:55TRUE1
24/02/20238:00TRUE1
24/02/20238:05TRUE1
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Even 2013 can handle this without VBA. Make a Shift table:
Book1
NOP
4ShiftStartEnd
5106:3114:30
6214:3122:30
7322:3106:30
Sheet3

Then just VLOOKUP the shift:
Book1
GHIJKL
4DateTimeEventShiftStartEnd
524/02/20236:30TRUE106:3114:30
624/02/20236:35TRUE106:3114:30
724/02/20236:40TRUE106:3114:30
824/02/20236:45TRUE106:3114:30
924/02/20236:50TRUE106:3114:30
1024/02/20236:55TRUE106:3114:30
1124/02/20237:00FALSE106:3114:30
1224/02/20237:05FALSE106:3114:30
1324/02/20237:10FALSE106:3114:30
1424/02/20237:15FALSE106:3114:30
1524/02/20237:20FALSE106:3114:30
1624/02/20237:25FALSE106:3114:30
1724/02/20237:30FALSE106:3114:30
1824/02/20237:35FALSE106:3114:30
1924/02/20237:40FALSE106:3114:30
2024/02/20237:45TRUE106:3114:30
2124/02/20237:50TRUE106:3114:30
2224/02/20237:55TRUE106:3114:30
2324/02/20238:00TRUE106:3114:30
2424/02/20238:05TRUE106:3114:30
Sheet3
Cell Formulas
RangeFormula
K5:K24K5=VLOOKUP([@Shift],Shifts,2,0)
L5:L24L5=VLOOKUP([@Shift],Shifts,3,0)

That said, I don't think we understand what you really need to do.
 
Upvote 0
That is a false condition? What does true mean?

Please share some desired end-result.
In the mentioned table, False condition means that production stops. Similarly, true condition means production goes on continuously with normal conditions. I want to extract start and end time for false condition so that i be able to calculate my production time loss in a shift.
 
Upvote 0
Even 2013 can handle this without VBA. Make a Shift table:
Book1
NOP
4ShiftStartEnd
5106:3114:30
6214:3122:30
7322:3106:30
Sheet3

Then just VLOOKUP the shift:
Book1
GHIJKL
4DateTimeEventShiftStartEnd
524/02/20236:30TRUE106:3114:30
624/02/20236:35TRUE106:3114:30
724/02/20236:40TRUE106:3114:30
824/02/20236:45TRUE106:3114:30
924/02/20236:50TRUE106:3114:30
1024/02/20236:55TRUE106:3114:30
1124/02/20237:00FALSE106:3114:30
1224/02/20237:05FALSE106:3114:30
1324/02/20237:10FALSE106:3114:30
1424/02/20237:15FALSE106:3114:30
1524/02/20237:20FALSE106:3114:30
1624/02/20237:25FALSE106:3114:30
1724/02/20237:30FALSE106:3114:30
1824/02/20237:35FALSE106:3114:30
1924/02/20237:40FALSE106:3114:30
2024/02/20237:45TRUE106:3114:30
2124/02/20237:50TRUE106:3114:30
2224/02/20237:55TRUE106:3114:30
2324/02/20238:00TRUE106:3114:30
2424/02/20238:05TRUE106:3114:30
Sheet3
Cell Formulas
RangeFormula
K5:K24K5=VLOOKUP([@Shift],Shifts,2,0)
L5:L24L5=VLOOKUP([@Shift],Shifts,3,0)

That said, I don't think we understand what you really need to do.
In the mentioned table, False condition means that production stops. Similarly, true condition means production goes on continuously with normal conditions. I want to extract start and end time for false condition so that i be able to calculate my production time loss in a shift.
 
Upvote 0
What are your expected results for the sample data in post #1 & why?
 
Upvote 0
What are your expected results for the sample data in post #1 & why?
I want to note the time when false condition starts and ends. Also, the total time consumed against false condition.

1678605299193.png
 
Upvote 0
Is this what you want then?

23 03 12.xlsm
ABCFGH
1DateTimeEventStartEndTotal
224/02/20236:30TRUE2023-02-24 07:00:002023-02-24 07:40:0000:40
324/02/20236:35TRUE
424/02/20236:40TRUE
524/02/20236:45TRUE
624/02/20236:50TRUE
724/02/20236:55TRUE
824/02/20237:00FALSE
924/02/20237:05FALSE
1024/02/20237:10FALSE
1124/02/20237:15FALSE
1224/02/20237:20FALSE
1324/02/20237:25FALSE
1424/02/20237:30FALSE
1524/02/20237:35FALSE
1624/02/20237:40FALSE
1724/02/20237:45TRUE
1824/02/20237:50TRUE
1924/02/20237:55TRUE
2024/02/20238:00TRUE
2124/02/20238:05TRUE
Start End
Cell Formulas
RangeFormula
F2F2=AGGREGATE(15,6,(A2:A21+B2:B21)/NOT(C2:C21),1)
G2G2=AGGREGATE(14,6,(A2:A21+B2:B21)/NOT(C2:C21),1)
H2H2=G2-F2
 
Upvote 0
Is this what you want then?

23 03 12.xlsm
ABCFGH
1DateTimeEventStartEndTotal
224/02/20236:30TRUE2023-02-24 07:00:002023-02-24 07:40:0000:40
324/02/20236:35TRUE
424/02/20236:40TRUE
524/02/20236:45TRUE
624/02/20236:50TRUE
724/02/20236:55TRUE
824/02/20237:00FALSE
924/02/20237:05FALSE
1024/02/20237:10FALSE
1124/02/20237:15FALSE
1224/02/20237:20FALSE
1324/02/20237:25FALSE
1424/02/20237:30FALSE
1524/02/20237:35FALSE
1624/02/20237:40FALSE
1724/02/20237:45TRUE
1824/02/20237:50TRUE
1924/02/20237:55TRUE
2024/02/20238:00TRUE
2124/02/20238:05TRUE
Start End
Cell Formulas
RangeFormula
F2F2=AGGREGATE(15,6,(A2:A21+B2:B21)/NOT(C2:C21),1)
G2G2=AGGREGATE(14,6,(A2:A21+B2:B21)/NOT(C2:C21),1)
H2H2=G2-F2
Yes, this helps me but if the false condition occurs twice or thrice in a shift or in a day (3 shifts in a day) then it would be a problem. What is the resolution for this problem? as i want separate entries for all the false events occurs in a day with the same pattern as you suggest for one event.

In below image, firstly false condition appears at 7:00-7:20 then again at 8:10-8:30. Now, how i got separate start and end time for these two events?

Kindly explain it according to the shifts as well (3-shifts in a day).

Shift-01 = 06:30-14:30
Shift-02 = 14:30-22:30
Shift-03 = 22:30-06:30

1678629328541.png
 
Upvote 0
but if the false condition occurs twice or thrice in a shift or in a day (3 shifts in a day) then it would be a problem.
.. then it probably would have been a good idea to have explained that at the beginning and/or included an example like that. ;)

23 03 12.xlsm
ABCFGH
1DateTimeEventStartEndTotal
224/02/20236:30TRUE2023-02-24 07:00:002023-02-24 07:40:0000:40
324/02/20236:35TRUE2023-02-24 07:50:002023-02-24 08:00:0000:10
424/02/20236:40TRUE   
524/02/20236:45TRUE   
624/02/20236:50TRUE
724/02/20236:55TRUE
824/02/20237:00FALSE
924/02/20237:05FALSE
1024/02/20237:10FALSE
1124/02/20237:15FALSE
1224/02/20237:20FALSE
1324/02/20237:25FALSE
1424/02/20237:30FALSE
1524/02/20237:35FALSE
1624/02/20237:40FALSE
1724/02/20237:45TRUE
1824/02/20237:50FALSE
1924/02/20237:55FALSE
2024/02/20238:00FALSE
2124/02/20238:05TRUE
22
Start End
Cell Formulas
RangeFormula
F2:F5F2=IFERROR(AGGREGATE(15,6,(A$2:A$21+B$2:B$21)/((C$2:C$21=FALSE)*(C$1:C$20<>FALSE)),ROWS(F$1:F1)),"")
G2:G5G2=IFERROR(AGGREGATE(15,6,(A$2:A$21+B$2:B$21)/((C$2:C$21=FALSE)*(C$3:C$22<>FALSE)),ROWS(F$1:F1)),"")
H2:H5H2=IF(G2="","",G2-F2)
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

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