Changing Hours, minutes, seconds to hours

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Hello
I am having trouble with vba to change:
2 Hour - 55 Minutes - 22 Seconds to an hour decimal, which equals 2.92 hours.

Any help is greatly appreciated.
Thank you
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
To convert time to a decimal take the time and divide by 24
eg: 2:55:22 x 24 = 2.92
make sure the result cell is formatted as a decimal number
 
Upvote 0
To convert time to a decimal take the time and divide by 24
eg: 2:55:22 x 24 = 2.92
make sure the result cell is formatted as a decimal number
Hello
The problem I'm running into, is the "Hour" "Minute" "Seconds" text.
If I have the problem in any given cell of XX Hour XX Minute XX Seconds. How do I get rid of the Text?
So 2 Hour - 55 Minutes - 22 Seconds = 2:55:22 so I can multiply by 24
Thanks for the help
 
Last edited:
Upvote 0
assuming
a1 = XX Hour
b1 = XX Minutes
c1 = XX Seconds

using your example 2 Hour - 55 Minutes - 22 Seconds

in cell D1 (make sure you format result cell as decimal number)
=(MID(A1,1,FIND(" ",A1)-1) & ":" & MID(B1,1,FIND(" ",B1)-1) & ":" & MID(C1,1,FIND(" ",C1)-1))*24
 
Upvote 0
i will have to play a little to extract it from a single cell
 
Upvote 0
When we are trying to a problem we are looking for patterns in the data and whether there are variations in that pattern and is there more data in the same cell around this.
Even in your last example I am confused as to whether it is "XX Hour XX Minute XX Seconds" OR "2 Hour - 55 Minutes - 22 Seconds".
So please provide some visibily of your data.
Also your initial posts indicates you are using VBA, so it would help to see the code that is dealing with this.

This is a bit long-winded but see if this helps.

VBA Code:
Sub ConvertTime()

    Dim strTime As String
    Dim splitTime As Variant
    Dim dblTime As Double

    strTime = ActiveCell.Value
    splitTime = Split(Trim(strTime), " ")
   
    dblTime = 24 * TimeSerial(splitTime(0), splitTime(2), splitTime(4))

    MsgBox "Time: " & dblTime
   
End Sub
 
Upvote 0
Will there always be an hour, minute, and second?

So if it was 55 minutes, would it say this:
0 hours - 55 minutes - 0 seconds
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top