Minutes And seconds in a userform textbox

mmmreece

New Member
Joined
Apr 8, 2015
Messages
34
Hi. I can't seem to find a solution to this. I need to enter a value from a userform textbox (or to as well) to a sheet. When entering on the userform, it works fine if I type "0:1:17" as 1 minute and 17 seconds but I only want to type "1:17" and have this entered to a cell on a sheet as the value meaning 1 minute and 17 seconds. However, everything I try to do fails. Mostly the entered result on the sheet turns out to be 17:00. Any ideas how to work around this?
Just to clarify as the above seems confusing. I want to enter a value similar to 1:17 representing 1 minute and 17 seconds to a userform text box and for this value (upon pressing a command button) to a cell on a sheet as 1:17 (meaning minutes and seconds)
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this (you can also just enter seconds):

VBA Code:
Dim strText as String
strText = TextBox1.Text    ' Change TextBox1 to your textbox's name.

Dim Count as Integer
Count = Len(strText)-Len(Replace(strText,":",""))

If Count = 0 then strText = "0:0:" & strText
If Count = 1 then strText = "0:" & strText

' Enter strText to the cell
 
Upvote 0
Try this (you can also just enter seconds):

VBA Code:
Dim strText as String
strText = TextBox1.Text    ' Change TextBox1 to your textbox's name.

Dim Count as Integer
Count = Len(strText)-Len(Replace(strText,":",""))

If Count = 0 then strText = "0:0:" & strText
If Count = 1 then strText = "0:" & strText

' Enter strText to the cell
That worked great. Thankyou
 
Upvote 0

Forum statistics

Threads
1,215,349
Messages
6,124,427
Members
449,158
Latest member
burk0007

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