VB and VBA Users Source Code: Excel VBA: Simple Formula to convert a times into total hours, minutes or seconds
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
VB/VBA Source Code
Excel VBA: Simple Formula to convert a times into total hours, minutes or seconds
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, November 07, 2007
Hits:
5087
Category:
VBA (Visual Basic for Applications)
Article:
Excel offers a number of useful built in formulas for manipulating dates and times, but does contain a simple function for taking a time (ie "10:00") and converting this into the number of minutes (eg 600 mins). The three functions below show you how to add your own custom formulea to perform this simple task: Function NumHours(timeSpan As Variant) As Variant Dim res As Double Application.Volatile True res = CDbl(timeSpan) * 24 NumHours = res End Function Function NumMins(timeSpan As Variant) As Variant Dim res As Double Application.Volatile True res = CDbl(timeSpan) * 24 * 60 NumMins = res End Function Function NumSecs(timeSpan As Variant) As Variant Dim res As Double Application.Volatile True res = CDbl(timeSpan) * 24 * 60 * 60 NumSecs = res End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder