userform textbox input hours

legi114

New Member
Joined
Mar 19, 2011
Messages
4
hello,

i made a userform calculator which adds hours to selected cells.
its based on MrExcels tutorial.
my problem is that the text box wont recognize hours in the format
as the cells have.
the format of the cells is [h]:mm for example i selected a cell with 24:50 ( 24 hours & 50 minutes) & a cell with 2000:05 ( 2000 hours & 5 minutes) i open the userform & i want to tipe in the textbox 11:30 & press on the cmdbutton and i want to get in the first cell that i selected the result of 36:20 & in the second cell that i selected the result of 2011:35.

the code i used in the cmdbutton :

for each cell in selection
cell.value = cell.value + textbox1.value
next cell

please help
thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi. Perhaps like this

Code:
cell.Value = cell.Value + TimeValue(textbox1.Value)
 
Upvote 0
a)a problem with this code it work only if i want to add up to 24:00 hours
when i try to add more than 24:00 hours a runtime error occurs.

any ideas how to make it an absolute time???

b) when i try to subtract time that larger from the time in the cell also a runtime error occurs ,
any idea how to allow it to calculate & show negative time such as: "-2:30" ?


thanks.
 
Upvote 0
Hi.

a) Maybe like this (untested)

Code:
cell.Value = cell.Value + CDate(textbox1.Value)

b) You cannot have negative time in Excel unless you use the 1904 time system.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

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