asked on # how do I convert to hours?

I want to convert the below column value into hours, can you please help?

2 weeks, 1 day, 6 hours, 30minutes

(1 week = 5 days) the above column should give me result in another column in hours. Please help me with formula.

2 weeks, 1 day, 6 hours, 30minutes

(1 week = 5 days) the above column should give me result in another column in hours. Please help me with formula.

Microsoft ExcelMicrosoft Office

This would be a lot easier / simpler in a VBA macro function that you could then call from a cell formula, but since you specifically asked for a formula approach, here is a sheet with the formula in it and a couple of test cases.

The text field must be of the following format or an error will be generated:

*aaa* weeks, *bbb* days, *ccc* hours, *ddd* minutes

EE29066936.xlsx

»*bp*

The text field must be of the following format or an error will be generated:

»

Hi Bill,

First of all thank you for your help.

These are the some possibilities for the column.

**Column A**

30 minutes

1 day, 1 hour

2 days, 30 minutes

1 week, 2 days, 30 minutes

3 weeks, 1 day, 1 minute

4 weeks, 2 days

1 week

Need to show the hour in Column B as you know.

And 1 day considered as 8 hours, did you already applied the logic in the formula?

can you give me the formula for the attached file? Thanks in advance.

For the empty cells, we need to show as 0 minutes/leave them as empty.

Hours-Calculation.xlsx

First of all thank you for your help.

These are the some possibilities for the column.

30 minutes

1 day, 1 hour

2 days, 30 minutes

1 week, 2 days, 30 minutes

3 weeks, 1 day, 1 minute

4 weeks, 2 days

1 week

Need to show the hour in Column B as you know.

And 1 day considered as 8 hours, did you already applied the logic in the formula?

can you give me the formula for the attached file? Thanks in advance.

For the empty cells, we need to show as 0 minutes/leave them as empty.

Okay, here is an update that should handle all of those, make sure the numbers are what you wanted. The formula is in the attached spreadsheet, and looks like this:

Hours-Calculation.xlsx

»*bp*

```
=IFERROR(LEFT(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (0)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (0)*LEN(A2)+1, LEN(A2)))))*INDEX({2400,2400,480,480,60,60,1,1},MATCH(TRIM(MID(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (0)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (0)*LEN(A2)+1, LEN(A2)))),999)),{"week","weeks","day","days","hour","hours","minute","minutes"},0)),0)+IFERROR(LEFT(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (1)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (1)*LEN(A2)+1, LEN(A2)))))*INDEX({2400,2400,480,480,60,60,1,1},MATCH(TRIM(MID(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (1)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (1)*LEN(A2)+1, LEN(A2)))),999)),{"week","weeks","day","days","hour","hours","minute","minutes"},0)),0)+IFERROR(LEFT(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (2)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (2)*LEN(A2)+1, LEN(A2)))))*INDEX({2400,2400,480,480,60,60,1,1},MATCH(TRIM(MID(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (2)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (2)*LEN(A2)+1, LEN(A2)))),999)),{"week","weeks","day","days","hour","hours","minute","minutes"},0)),0)+IFERROR(LEFT(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (3)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (3)*LEN(A2)+1, LEN(A2)))))*INDEX({2400,2400,480,480,60,60,1,1},MATCH(TRIM(MID(TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (3)*LEN(A2)+1, LEN(A2))), FIND(" ", TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",LEN(A2))), (3)*LEN(A2)+1, LEN(A2)))),999)),{"week","weeks","day","days","hour","hours","minute","minutes"},0)),0)
```

»

And just comparison here is an approach using a User Defined Function in VBA macro to do the calculation. Spreadsheet attached with a new column calculated using this approach, and containing the macro shown below.

Hours-Calculation.xlsm

»*bp*

```
Public Function CalcMinutes(strText As String) As Variant
Dim arrChunk() As String
Dim strChunk As Variant
Dim arrWord() As String
CalcMinutes = 0
If strText = "" Then Exit Function
arrChunk = Split(strText, ",")
For Each strChunk In arrChunk
arrWord = Split(Trim(strChunk), " ")
If UBound(arrWord) <> 1 Then
CalcMinutes = CVErr(xlErrNA)
Exit Function
End If
Select Case LCase(arrWord(1))
Case "minute", "minutes"
If IsNumeric(arrWord(0)) Then
CalcMinutes = CalcMinutes + CInt(arrWord(0))
Else
CalcMinutes = CVErr(xlErrNA)
Exit Function
End If
Case "hour", "hours"
If IsNumeric(arrWord(0)) Then
CalcMinutes = CalcMinutes + (CInt(arrWord(0)) * 60)
Else
CalcMinutes = CVErr(xlErrNA)
Exit Function
End If
Case "day", "days"
If IsNumeric(arrWord(0)) Then
CalcMinutes = CalcMinutes + (CInt(arrWord(0)) * 480)
Else
CalcMinutes = CVErr(xlErrNA)
Exit Function
End If
Case "week", "weeks"
If IsNumeric(arrWord(0)) Then
CalcMinutes = CalcMinutes + (CInt(arrWord(0)) * 2400)
Else
CalcMinutes = CVErr(xlErrNA)
Exit Function
End If
Case Else
CalcMinutes = CVErr(xlErrNA)
Exit Function
End Select
Next
End Function
```

»

Hi Bill,

Thank you very much!! I am wondering by seeing that formula, It is working as expected :)

Can I ask you one more help?

Please find the attached file, we need to calculate the total time spent based on Main ticket# in the sheet of Main by comparing the same to the next sheet of Sub.

1 week = 5 days

1 day = 8 hours as you know.

Main sheet > C2 = addition of Sub sheet > C column based on Main sheet > Main ticket column.

Please give me the result C2 same like B2 by calculating all the sub tickets in the next sheet based on Main Ticket.

Remaining time we need calculate B2-C2 = D2

Thanks,

Surendar

Hours-Calculation.xlsx

Thank you very much!! I am wondering by seeing that formula, It is working as expected :)

Can I ask you one more help?

Please find the attached file, we need to calculate the total time spent based on Main ticket# in the sheet of Main by comparing the same to the next sheet of Sub.

1 week = 5 days

1 day = 8 hours as you know.

Main sheet > C2 = addition of Sub sheet > C column based on Main sheet > Main ticket column.

Please give me the result C2 same like B2 by calculating all the sub tickets in the next sheet based on Main Ticket.

Remaining time we need calculate B2-C2 = D2

Thanks,

Surendar

Hi Bill,

Thank you, sorry I should have informed you earlier.

I need C,D and E column in the format of B column > weeks,days,hours,minutes

1 week - 5 days

1 day - 8 hours

Can you please help.

Thanks,

Surendar

Thank you, sorry I should have informed you earlier.

I need C,D and E column in the format of B column > weeks,days,hours,minutes

1 week - 5 days

1 day - 8 hours

Can you please help.

Thanks,

Surendar

Sorry for the re-work Bill, the last request should be my final one.

I am very thankful for you.

Thanks,

Surendar

I am very thankful for you.

Thanks,

Surendar

Working it...

»*bp*

»

These formulas are getting very large and complicated, are you sure you want to solve this with formulas rather than VBA user defined functions?

»*bp*

»

Here is what I have so far. The calculated columns in hours (highlighted in yellow) are needed to drive the "text" versions of those, but you can of course hide those columns so they aren't visible.

(I did adjust some of the data on the second sheet just to get some more interesting values on the first sheet)

Hours-Calculation.xlsx

»*bp*

(I did adjust some of the data on the second sheet just to get some more interesting values on the first sheet)

»

Hi Bill,

Thank you :)

Seems we need to correct minus values, when it crosses the original estimation.

Here is the output I have, please find the attached file.

I have added some comments for you, if possible can you please help on that.

Thanks,

Surendar

Hours-Calculation.xlsx

Thank you :)

Seems we need to correct minus values, when it crosses the original estimation.

Here is the output I have, please find the attached file.

I have added some comments for you, if possible can you please help on that.

Thanks,

Surendar

View this solution by signing up for a free trial.

Members can start a 7-Day free trial and enjoy unlimited access to the platform.

Hi Bill,

I don't see formula in the excel, can you please check.

The result in the excel looks fine.

Thanks,

Surendar

I don't see formula in the excel, can you please check.

The result in the excel looks fine.

Thanks,

Surendar

Formula is there, but I left it as multi-line format since that makes it much easier to follow. I typically work with large formulas like this in a text editor and then paste in to Excel.

To see the full formula you can expand the formula bar by using the small**v** icon (see picture below).

Or, when on the cell you can press**F2** and see the full formula on top of the spreadsheet.

»*bp*

To see the full formula you can expand the formula bar by using the small

Or, when on the cell you can press

»

Thanks a lot :)

You are great!!!! I don't know what to say. I will never forget your help.

You are great!!!! I don't know what to say. I will never forget your help.

2 weeks, 1 day, 6 hours, 30 minuteswith that spacing, and commas, etc? And is that always true? And will all 4 pieces always be present, even if say minutes was 0?

»

bp