You are here:

Excel/# of minutes greater than in a column


QUESTION: Good day,

Let's say that I have data with timestamps in a an Excel spreadsheet in column A and I want to know how many times the minutes "mm" in hh:mm:ss were greater than "5" minutes as in below timestamps.
Just by looking we know that it is 3 times, but I want to find a formula to find it as in =COUNTIF(A1:A25)...etc.
Excel beginner
Excel 2010 for windows



ANSWER: Hi Pablo,

Here is a user-defined function (UDF) that will count these for you.  In your case you can use it like this:


The first argument is the range containing all the times, and the second argument is the number which the minutes in the time value must exceed to be counted.

Here is the code:

Function NumMin(TimeRng As Range, MaxMinutes As Integer) As Long
  'returns the number of time values in range TimeRng whose minutes
  'part exceeds MaxMinutes
  Dim Cell    As Range 'a cell in TimeRng
  NumMin = 0
  For Each Cell In TimeRng
     If Minute(Cell) > MaxMinutes Then NumMin = NumMin + 1
  Next Cell
End Function

You can simply paste this code into a standard macro module and this UDF will be immediately available.


---------- FOLLOW-UP ----------


What about if I wanted to find how many times the minutes and seconds "mm:ss" were greater than "6:59" 6 minutes and 59 seconds with the timestamps above?


ANSWER: Hi again Pablo,

Here is a modified UDF that you can use to do what you describe:

Function NumMinSec(TimeRng As Range, MaxTime As Date) As Long
 'returns the number of time values in range TimeRng whose minutes
 'part exceeds MaxMinutes (actually a string representation of a
 'time value, such as "06:59"
 Dim Cell    As Range 'a cell in TimeRng
 NumMinSec = 0
 For Each Cell In TimeRng
    If StripHours(Cell.Value) > CDate(MaxTime) Then NumMinSec = NumMinSec + 1
 Next Cell
End Function

Function StripHours(T As Date) As Date
  'strips hours off of time value, leaving only minutes and seconds.
  'example, 14:06:21 yields a time value of 06:21
  StripHours = T - Hour(T) / 24
End Function

Note that you must include the StripHours helper function.

When you use this function you must specify the hours and minutes of the max hour and minute value including a leading zero for the hour value as a text string like this:



---------- FOLLOW-UP ----------

QUESTION: Great Damon, it works well! Much appreciated! Now my last question (hopefully):)

What about if I want to compare two columns and find the # of times the time in column B is greater than column A by 5 minutes.

d/h:m   h:m:s
10307   3:08:44
10320   3:22:08
10348   3:56:43
10635   6:36:28
10650   6:55:02
10719   7:20:59
10730   7:36:36
10845   8:46:21
11032   10:33:58
11241   12:43:32
11620   16:22:01
11715   17:20:10
11734   17:36:40
11745   17:46:19
11835   18:36:46
30209   2:10:11
40341   3:42:35
40550   5:51:47
41623   16:23:55
41721   17:22:12
41824   18:25:16
41947   19:49:02
42021   20:26:59
50150   1:51:19
62113   21:14:35
70145   1:46:44
70210   2:11:59
70317   3:24:02
70546   5:47:44
70634   6:36:07
70827   8:28:53
70854   8:57:22
71125   11:26:13
71740   17:41:43
72057   20:58:33
81145   11:46:43
81241   12:42:11
81406   14:07:13
81513   15:13:39
81715   17:15:50

Thank you!


Hi again Pablo,

Here's some code:


Function NumDif(TimeRng As Range, MaxDif As Single) As Long
 'returns the number of time values in the second column of range TimeRng
 'exceeds the values in the first column of TimeRng by more than MaxDif,
 'a decimal number of minutes.
 Dim Cell     As Range 'a cell in TimeRng
 Dim MaxDifD  As Date  'MaxDif value in days
 MaxDifD = MaxDif / 1440#
 NumDif = 0
 For Each Cell In TimeRng.Columns(2).Cells
    If Cell - Cvt2Date(Cell.Offset(0, -1).Text) > MaxDifD Then NumDif = NumDif + 1
 Next Cell
End Function

Function Cvt2Date(DHM As String) As Date
  'converts 5-6 digit numbers to h:m assuming numbers are in the form
  'ddhhmm (e.g., 41947 is equivalent to 19h 47m)
  Dim MM      As Integer
  Dim HH      As Integer
  MM = CInt(Right(DHM, 2))
  HH = CInt(Left(Right(DHM, 4), 2))
  Cvt2Date = TimeSerial(HH, MM, 0)
End Function

In this case you would call the UDF like this:


Note that the decimal part of the minutes (5.0) does matter, so for example 5.1 would indicate a time difference of 5 minutes 6 seconds.

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here


All Answers

Answers by Expert:

Ask Experts


Damon Ostrander


I have extensive experience with VBA programming in Excel 5 through Excel 2013. As a former aerospace engineer with a large aerospace corporation and consultant in a small defense technology services company, I have developed a wide range of applications in VBA, including simulations involving mixed-language programming, satellite orbit mechanics, graphics and animation, and real-time applications. I am interested in moderate to hard VBA-related questions only.


I have developed and taught several courses in Excel VBA programming and also VBA programming in Office 97, 2000, and 2007. I have developed a number of large technical applications in Excel VBA for use within the aerospace industry.

B.S. in Electrical Engineering and Computer Science, University of California, Berkeley.

©2016 All rights reserved.