Timer mm:ss in textbox VBA

MmonkeyDX

New Member
Joined
Feb 18, 2021
Messages
2
Office Version
  1. 2019
Platform
  1. Windows
Hi all,
I have a problem with textboxes in userform.
Basically i just want to display one cell with a timer inside through one textbox in my userform.

In C2 i have a timer and the cell format is "mm:ss", so the textbox2 should display that cell in that format but it seems so complicate.
If the "ControlSource" of textbox2 is C2, then the value is something like this: "6,94444444444444E-05".
So i've used the code below but the timer goes mad and goes directly to 12:00:00 in the c2 cell and 0,5 in the textbox
VBA Code:
Private Sub TextBox2_Change()
    TextBox2 = Format(TextBox2, "mm:ss")
End Sub

With this code there are no problems and the time is shown in hh:mm:ss but i need mm:ss
Code:
Private Sub TextBox2_Change()
    TextBox2 = Format(TextBox2, "hh:mm:ss")
End Sub

So i've changed it to
Code:
Private Sub TextBox2_Change()

TextBox2 = Right(Format(TextBox2, "hh:mm:ss"), 5)

End Sub

In this way the hours are hidden but the timer is freezed to 00:00 and i don't know why

Any solution for this problem? I can't belive there isn't an easy way to display in a textbox the content of a cell with timer inside.
Thank you so much for help
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
can you run the timer on the userform. the removes the linking problem you are having
 
Upvote 0
Of course this is an option, but i think that the textbox format problem's still remain :/
 
Upvote 0
thats is the point. unlink the textbox from the worksheet. run the timer on the userform and update the cell periodically. i assume the userform is the front window, so if the sheet is not updated every second it wont matter anyway.
 
Upvote 0
This thread may be a bit old, though I was having the same problem and found some code for show/hide of a userform for X amount of seconds.
Here is my adaptation of that code and it works great by simply applying text and removing the text at a given interval

Public SchTime

Sub ShowTB()
UserForm1.TextBox81 = "PASSWORD ACCEPTED"
SchTime = Now + TimeValue("00:00:05")
Application.OnTime SchTime, "HideTB"
End Sub

Sub HideTB()
UserForm1.TextBox81 = ""
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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