getting the hour number out of string of characters

bartvdg

Board Regular
Joined
Sep 27, 2009
Messages
65
I have some excel data with shows up in this format:
[TABLE="width: 133"]
<tbody>[TR]
[TD="class: xl65, width: 133"]PT1H11M47S[/TD]
[/TR]
</tbody>[/TABLE]

I would like to extract the number before the letter "H", in this example result needs to be 1

I can do this by using two formulas:
=TRIM(SUBSTITUTE(P16;"PT";"")) removes PT ---> 1H11M47S
=LEFT(Q16;VALUE(FIND("H";Q16;1))-1) shows the result ---> 1

I'm not succeeding in merging the 2 formulas, or maybe there is an easier way to do this?
Thanks!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Here are more examples and the desired outcome, your formula only brought one number

[TABLE="width: 266"]
<colgroup><col span="2"></colgroup><tbody>[TR]
[TD]Time with Agent[/TD]
[TD]Hours with Agent[/TD]
[/TR]
[TR]
[TD]PT1000H11M47S[/TD]
[TD="align: right"]1000[/TD]
[/TR]
[TR]
[TD]PT53H11M47S[/TD]
[TD="align: right"]53[/TD]
[/TR]
[TR]
[TD]PT1H11M47S[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]PT8M51S[/TD]
[TD="align: right"]0[/TD]
[/TR]
[TR]
[TD]PT33M27S[/TD]
[TD="align: right"]0[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Hi,

I'd imagine you would want the formula results converted to Real Numbers for further math/comparisons, just add +0 :

=IFERROR(MID(P11;3;FIND("H";P11)-3)+0;0)
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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