find number of times a value occurs in between times

pyclen

Board Regular
Joined
Jan 17, 2022
Messages
91
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi All,

I have a series of Excel files with two columns, Column A is the date/time the other column is bpm (beats per minute) as shown below, there are >12k values per day so I am not posting the whole file. The columns are column A & B.

my question now is how can I determine the number of times the bpm is greater than 90 for example in between two times, (lets say 3-4am)

any help is appreciated
dateTimebpm
07/09/23 04:00:02
68​
07/09/23 04:00:07
71​
07/09/23 04:00:12
70​
07/09/23 04:00:17
68​
07/09/23 04:00:22
67​
07/09/23 04:00:27
67​
07/09/23 04:00:32
69​
07/09/23 04:00:37
70​
07/09/23 04:00:42
68​
07/09/23 04:00:47
67​
07/09/23 04:00:57
68​
07/09/23 04:01:12
68​
07/09/23 04:01:17
69​
07/09/23 04:01:27
68​
07/09/23 04:01:32
66​
07/09/23 04:01:42
65​
07/09/23 04:01:52
66​
07/09/23 04:01:57
68​
07/09/23 04:02:07
64​
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Check the next example:

varios 14jul2023.xlsm
ABCDE
1dateTimebpmStart time:07/09/2023 04:00:12
207/09/2023 04:00:0268End time:07/09/2023 04:00:57
307/09/2023 04:00:0771bpm >68
407/09/2023 04:00:1270Count:3
507/09/2023 04:00:1768
607/09/2023 04:00:2267
707/09/2023 04:00:2767
807/09/2023 04:00:3269
907/09/2023 04:00:3770
1007/09/2023 04:00:4268
1107/09/2023 04:00:4767
1207/09/2023 04:00:5768
1307/09/2023 04:01:1268
1407/09/2023 04:01:1769
1507/09/2023 04:01:2768
1607/09/2023 04:01:3266
1707/09/2023 04:01:4265
1807/09/2023 04:01:5266
1907/09/2023 04:01:5768
2007/09/2023 04:02:0764
21
Hoja2
Cell Formulas
RangeFormula
E4E4=COUNTIFS(A:A,">="&E1,A:A,"<="&E2,B:B,">"&E3)



In cells E1 to E3 you can put the values you need to count.

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Upvote 0
Solution
paste macro into a module.

sheet: DATA
has your bpm data

sheet: MAIN
holds the seach criteria:

B2 = start time: 3 am
B3 = end time: 4 am

B6 = operator : >
C6 = BPM value to search

enter the values then run: FindBpm

Code:
Option Explicit

Private mvStartTime As Date, mvEndTime As Date, mvTime As Date
Private mvOper
Private miTargBPM As Integer, miBpm As Integer
Private Const kFOUND = "FOUND"
Sub FindBpm()
' FindBpm Macro


mvStartTime = Range("B2").Value
mvEndTime = Range("B3").Value

mvOper = Range("B6").Value
miTargBPM = Range("C6").Value

Worksheets("Data").Select
Columns("C:C").ClearContents

Range("A2").Select
Range("C1").Value = "Found"

While ActiveCell() <> ""
  mvTime = Format(ActiveCell.Value, "h ampm")
  miBpm = Val(ActiveCell.Offset(0, 1).Value)
  
  If mvTime >= mvStartTime And mvTime <= mvEndTime Then
      Select Case mvOper
         Case "="
           If miBpm = miTargBPM Then GoSub FountIT
         Case "<"
           If miBpm < miTargBPM Then GoSub FountIT
         Case ">"
           If miBpm > miTargBPM Then GoSub FountIT
         Case "<="
           If miBpm <= miTargBPM Then GoSub FountIT
         Case ">="
           If miBpm >= miTargBPM Then GoSub FountIT
       End Select
   End If

  ActiveCell.Offset(1, 0).Select 'next row
Wend
Exit Sub

FountIT:
 ActiveCell(0, 3).Value = kFOUND
Return
End Sub
 
Upvote 1
Thank you, appreciate the macro

will let it run on a data set, and see what happens
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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