Add 10 minutes to time in userform

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
Hi All,

I would like a vba script that will add 10 minutes to the time that I have in a userform textbox, but also the option to add 9 mins 34 secs etc...

This has been covered in other posts except my time needs to be in a specific format as follows.

I am using a wintimer and the time is displayed as.

Code:
strTime = Split(Format$(Now, "h:mm:ss am/pm"))(0)

I want the time to be displayed this way i.e 1:26:50 (without am/pm on the end).

Thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I'm not sure whether you still need to know how to add the time or not, but as for your time format, does this output the time that you need...

Code:
strTime = Left(Time, Len(Time) - 3)
 
Upvote 0
Hi Rick, the strtime is correct, I just need to be able to deduct an amount of time from it.

I have tried scripts but if say one time is 12.56 and the 2nd is 1.16 I end up with a different subtraction total value than if the time was 12.36 and the time to deduct it from was 12.46.

For instance one total ends up as 570 the other is 4980
 
Upvote 0
Maybe this will explain it better.

I have the time/ strtime stored as a value in textbox1.

So the value stored is i.e 2:39:01

I want textbox2 to be 2:39:01 + 9 mins and 30 secs, so textbox2.value would = 2:48:31.


Code:
Dim strTime As String
strTime = Split(Format$(Now, "h:mm:ss am/pm"))(0)
TextBox1.Value = strTime
TextBox2.Value = textbox1.value + 9.30
 
Upvote 0
Jaye7,

Does this work:

I could not figure out how to add the 9 min 30 sec to your time format, but what I did instead was added 9 min 30 sec to the time, "then" converted it to your required format as follows:

Code:
strTime = [COLOR=black]Now[/COLOR]() + TimeValue("00:09:30")
strTime = Split(Format$([COLOR=red]strTime[/COLOR], "h:mm:ss am/pm"))(0)
Notice I replaced your Now with strTime in that 2nd line
Chuck
 
Upvote 0
I want textbox2 to be 2:39:01 + 9 mins and 30 secs, so textbox2.value would = 2:48:31.

Code:
Dim strTime As String
strTime = Split(Format$(Now, "h:mm:ss am/pm"))(0)
TextBox1.Value = strTime
TextBox2.Value = textbox1.value + 9.30
You need to use the TimeSerial function to create the 9 minute 30 second offset time and apply the CDate function to the TextBox string value to make it into a real date/time value.

Code:
  TextBox2.Value = CDate(TextBox1.Value) + TimeSerial(0, 9, 30)
 
Upvote 0
Thanks everyone,

I will check out these scripts tomorrow and let you know the outcome.
 
Upvote 0
I would like to suggest you change your code to this...

Code:
Dim dtTime As Date, dtNewTime As Date
dtTime = Now
TextBox1.Value = Split(Format$(dtTime, "h:mm:ss am/pm"))(0)
dtNewTime = dtTime + TimeSerial(0, 9, 30)
TextBox2.Value = Split(Format$(dtNewTime, "h:mm:ss am/pm"))(0)
otherwise I think adding the new time to the old time might reintroduce the AM/PM designation if the time you are adding ends up crossing noon or midnight.
 
Upvote 0
Jaye7,

This might be all that is needed:
Code:
Dim strTime As String
strTime = Now() + TimeValue("00:09:30")
strTime = Split(Format$(strTime, "h:mm:ss am/pm"))(0)
textbox1.Value = strTime

Going past midnight with the extra 9 min 30 sec should still work ok too.
 
Last edited:
Upvote 0
@chuckchuckit,

Did you notice that the OP is using two separate TextBoxes, one to display the before time and the other to display the after time?
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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