Calculate Difference Between two Times in Excel VBA. Most of the time we wanted find differences of two Times. It’s a very regular and common exercise in Excel and VBA when dealing with times. We can find this using Excel VBA DateDiff function. In order to calculate we need start time and end time. It returns an integer value as a result.
Let us see the macro to calculate Difference Between two Times in Excel VBA.
'Calculate Difference Between two Times in Excel VBA Sub VBA_Calculate_Difference_Between_Two_Times() 'Variable declaration Dim sDate As Date, eDate As Date Dim iValue As Integer 'Start Date sDate = "8:10:00" 'End Date eDate = "12:10:00" iValue = DateDiff("h", sDate, eDate) 'Display output on the screen MsgBox "The Difference Between two Times in hours : " & iValue, vbInformation, "Difference Between two Times in Hours" End Sub
Here is the output screenshot of above macro.
You can refer the following link for the step by step instructions.
Click on the following links of the useful resources. These helps to learn and gain more knowledge.