Find Duration in Hours between two Dates using VBA

Could you help me in finding the duration in hours between two dates using VBA code? I have a range of dates as a text file. I have the start date and the end date. The dates are written as 05-Jan-2012 9:15 and 14-Jan-2012 8:10 for example, and I’m supposed to find the total time in hours between the two dates.
Thanks in advance! 🙂

First we need to import the data from the text file into an Excel worksheet
We then write the VBA Code
VBA code: Sub calculateHours()
Range(“C1”).Value = (Range(“B1”).Value – Range(“A1”).Value) * 24
End Sub
We subtract the start date from the end date and multiply the result by 24
If you had more data in the text file then you would need to use a ‘do while’ or ‘for loop’ to perform all the calculations

Watch the training video below to learn how to find total number of hours between two dates:

One thought on “Find Duration in Hours between two Dates using VBA

  1. Pingback: Best Training on Advanced Excel and VBA in Bangalore | jaseemblog

Leave a Reply

Your email address will not be published. Required fields are marked *