Calculate Minutes Between two Times in Excel VBA

Calculate Minutes Between two Dates

Calculate Minutes Between two Times in Excel VBA using VBA formulas. We use DateDiff VBA Function to determine the number of Minutes between two Times. In order to calculate number of Minutes between two Times we need start time and end time. It returns an integer value as a result. We use DateDiff function in Excel to perform same task in Excel.

Macro to Calculate Number of Minutes Between two Times in Excel VBA

Let us see the macro to count number of Minutes Difference Between two Times in Excel VBA.

'Calculate Minutes Between two Times in Excel VBA
Sub VBA_Calculate_Minutes_Between_Two_Times()
    
    'Variable declaration
    Dim sTime As Date, eTime As Date
    Dim iValue As Integer
    
    'Start Time
    sTime = "10:10:00"
    
    'End Time
    eTime = "11:10:00"
    
    iValue = DateDiff("n", sTime, eTime)
    
    'Display output on the screen
    MsgBox "The number of minutes between two Times : " & iValue, vbInformation, "Minutes Between Two Times"
    
End Sub

Here is the output screen shot of above macro.
Calculate Minutes Between two Dates

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog

1 thought on “Calculate Minutes Between two Times in Excel VBA”

  1. One small problem: if the sTime is “PM” and eTime is “AM” the result is negative minutes and incorrect.
    Ex: 1:23PM to 2:45AM is 12 hours and 71 minutes for a total of 791 minutes. Using the example shown returns -649 minutes; this calculation is the result if start and end are reversed.
    Is there a way to correct for this?

Leave a Comment