Count data between date and time stamps

jedilefty

New Member
Joined
Nov 14, 2017
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Hello everyone! I have an issue I need help with. I need to count how many transactions are created between a date with a time stamp. Date format is in month/day/year followed by time in 24hr format. Here is what the column in my sheet look like. Any help would be greatly appreciated!!
1658510926255.png
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
jed Let's get the ball rollin. Now this usually generates more questions than answers, but we have to start some place. Sometimes the A plus students weigh in and will post a program that does the same as this one, only they will do in 2 lines of code. Anyway let us know if this is a good solution to your problem. Oh I should mention that this only works if you sort the day and time. Like I did. If this is a problem let us know.


VBA Code:
Sub Prog1()

Dim Count As Long
Dim LastCell As Long
Dim i As Long
Dim h As Long

LastCell = Cells(Rows.Count, "A").End(xlUp).Row

Count = 1

For i = 4 To LastCell

If Cells(1, 1) < Cells(i, 1) Then

Cells(i, 1).Select
Exit For
End If

Next i

h = i

Count = 1
For i = h To LastCell

If Cells(2, 1) >= Cells(i + 1, 1) Then

Cells(i + 1, 1).Select
Count = Count + 1
End If
Next i

Range("C2") = Count

Range("A1").Select

End Sub

22-07-22.xlsm
ABC
17/21/2022 6:08
27/21/2022 11:18count4
3
47/21/2022 5:06
57/21/2022 5:07
67/21/2022 5:08
77/21/2022 5:14
87/21/2022 5:17
97/21/2022 5:23
107/21/2022 5:47
117/21/2022 6:08
127/21/2022 8:42
137/21/2022 11:18
147/21/2022 11:18
157/21/2022 12:35
167/21/2022 12:47
177/21/2022 12:48
187/21/2022 12:51
197/21/2022 13:38
207/21/2022 16:16
217/21/2022 16:16
227/21/2022 20:00
237/21/2022 20:36
247/21/2022 22:41
257/21/2022 23:52
267/21/2022 23:52
Data
 
Upvote 0
Do the times in the Input boxes for first and last time have dates entered or just times ?
If just times then how does the formula or code know which date to use or is it just counting between those times for all days in that column ?

If it applies to all days you could try something like this.
Where A1 = Shift Start and A2 = Shift End
Excel Formula:
=COUNT(FILTER($A$4:A26,(MOD($A$4:$A$26,1)>MOD($A$1,1))*(MOD($A$4:$A$26,1)<MOD($A$2,1)),""))
 
Upvote 0
Solution
Do the times in the Input boxes for first and last time have dates entered or just times ?
If just times then how does the formula or code know which date to use or is it just counting between those times for all days in that column ?

If it applies to all days you could try something like this.
Where A1 = Shift Start and A2 = Shift End
Excel Formula:
=COUNT(FILTER($A$4:A26,(MOD($A$4:$A$26,1)>MOD($A$1,1))*(MOD($A$4:$A$26,1)<MOD($A$2,1)),""))
Thanks Alex!! This worked out perfectly!! Much appreciated!!
 
Upvote 0

Forum statistics

Threads
1,214,517
Messages
6,119,984
Members
448,935
Latest member
ijat

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