Commandbutton to enter current time

RPT_22

Board Regular
Joined
Sep 18, 2012
Messages
98
Hi,

I have created a userform but need help inserting code

1. I have commandbutton1 placed on a userform labelled Enter Time
2. When Enter Time button pressed, i need the current time to be entered into Textbox 1

Once time is entered into textbox1, i don`t want the time to change [remain static] as i may not send the userform data for up to 1 hour

Is this possible....thank you
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi try this
VBA Code:
Private Sub CommandButton1_Click()
TextBox1.Value = Split(Now())(1)
End Sub
 
Upvote 0
Well
NOW() will give you
11/20/2021 9:59​

Split do divide to an Array Array(0)= 11/20/2021 & Array(1)=9:59
So array(1) is what you want
 
Upvote 0
Solution

Forum statistics

Threads
1,214,812
Messages
6,121,696
Members
449,048
Latest member
81jamesacct

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