ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   TextBox in UserForm with 24h time format (https://www.excelbanter.com/excel-programming/322150-textbox-userform-24h-time-format.html)

mika

TextBox in UserForm with 24h time format
 
Hi,

I would like to sum up several time values from different
cells (more than 24 h) and output them into a TextBox
(UserForm).

The result should be 26:30 but the TextBox shows 09:30.

I tried it like:
TextBox1 = Format(Application.Sum(Range _
("A1:A10")), "hh:mm")

Unfortunately it doesn't work.

I tried it with the format [h]:mm but it shows :12.

Is there a possibility to get the needed formatting?

Thanks for your help,
Mika

Tom Ogilvy

TextBox in UserForm with 24h time format
 
One way:

Dim dblTime as Double
Dim lDays as long, lHours as long, lMinutes as long
dblTime = Format(Application.Sum(Range _
("A1:A10")), "hh:mm")
lDays = Int(dblTime)
lhours = hour(dblTime-int(dblTime))
lMinutes = minute(dblTime-int(dblTime))
Textbox1.Text = lDays*12+lHours & ":" & format(lMinutes,"00")

--
Regards,
Tom Ogilvy



"Mika" wrote in message
...
Hi,

I would like to sum up several time values from different
cells (more than 24 h) and output them into a TextBox
(UserForm).

The result should be 26:30 but the TextBox shows 09:30.

I tried it like:
TextBox1 = Format(Application.Sum(Range _
("A1:A10")), "hh:mm")

Unfortunately it doesn't work.

I tried it with the format [h]:mm but it shows :12.

Is there a possibility to get the needed formatting?

Thanks for your help,
Mika





All times are GMT +1. The time now is 07:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com