Converting durations to minutes

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,252
Good morning,

I have a series of time values which are formatted thus e.g. 28hr 46m 22s

I have some code that builds up a string containing the "minute" vales of these strings, so, for example 10h 15m 17s would display as 615 (10*60+15)

I achieve this with:
Code:
MinuteValue = (Hour(Selection) * 60) + Minute(Selection)
This works fine as long as the value doesn't exceed 24 hours - 28hr 46m 22s for example returns 286 when it should be 1726 (28*60)+46
Do any of you nice folk have a suggestion as to how I can alter my code to include up the days correctly?

Thanks in advance

Pete
 

Some videos you may like

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
1,026
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
Hi there. Try: MinuteValue = Round(MySelection * 60 * 24, 0) (I have changed the name you used as it is a word used in Excel and I always try to avoid using names like that).
 

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,252
John - perfect! :) I was only using "Selection" whilst I was testing the code manually on selected cells, but thanks for the spot nevertheless!
Pete
 

jmacleary

Well-known Member
Joined
Oct 5, 2015
Messages
1,026
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
You're welcome and thanks for the feedback (I was very lazy and didn't use code tags - naughty!
 

Watch MrExcel Video

Forum statistics

Threads
1,109,451
Messages
5,528,822
Members
409,839
Latest member
akashsadhu
Top