Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - convert "1 hour, 20 minutes" to 1.33 1

Status
Not open for further replies.

keun

Technical User
Jul 15, 2005
262
US
I get data like this:

Code:
0 hours, 7 minutes
0 hours, 44 minutes
1 hour, 53 minutes
0 hours, 1 minute

I want to convert it to decimals. Right now I use Text to Columns, Find/Replace to get rid of the hours and minutes text, convert the minutes to a fraction of an hour, and then add the two columns back together.

There must be a way to do this on one function. Anyone got any ideas?

I joined this forum in 2005. I am still a hack.
 
Code:
Sub timefraction()
theColumnwiththeNumbers = 1

For x = 1 To Application.ActiveSheet.UsedRange.Rows.Count - 1
    theValue = Application.ActiveSheet.Cells(x, theColumnwiththeNumbers)
    
    theSplit = Split(theValue, Chr(32), , vbTextCompare)
    
    theH = theSplit(0)
    theM = theSplit(2)
    theD = Round((theM / 60), 2)
    theV = theH + theD
    Application.ActiveSheet.Cells(x, theColumnwiththeNumbers + 1).Value = theV
Next x





End Sub
 
Code:
=INT(LEFT(B2,2))+INT(MID(B2,FIND(", ",B2)+2,2))/60

wow

I joined this forum in 2005. I am still a hack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top