Date and Time on a Userform

Gregs

Board Regular
Joined
Sep 6, 2002
Messages
96
Hi Mr Excel,

How do I put the current date and time on a userform say in a textbox and each time I bring up the userform it refreshes.

Any help would be appreciated
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
try now()
you can use the now() function in a cell and then link the text box to that cell
 
Upvote 0
you can place this code in any event
for example say you have a button that refreshes your form and your current date and time need to be stored in a text box named "TextBox1" you can place the following code in the click event of the Button


Dim CurTimeDate As String
CurTimeDate= Now()
TextBox1 = CurTimeDate

each time the button is clicked the textbox will capture the current date and time

Hope this helps

let me know if you need more info
 
Upvote 0
Hello, you could also use a pure programatic solution by placing code like the following in your userform module:

<pre>
Private Sub userform_initialize()
TextBox1 = Now
End Sub</pre>

Where you adjust the code for the correct name of the textbox. A label would work as well...
 
Upvote 0
On the same lines as Nato but just to make sure the format is OK for your region try this:

Private Sub UserForm_Initialize()
TextBox1.Value = Format(Now, "ddd dd-mmm-yyyy hh:mm")
End Sub

This will give you Thu 20-Sep-2002 00:15

Cheers

Ryan UK :)
 
Upvote 0
Good thinking Ryan, the format is one that I'm accustomed to, didn't think of it.

Have a good one!

Cheers,

North Atlantic Treaty Organization :biggrin:
This message was edited by NateO on 2002-09-19 17:38
 
Upvote 0
Thanks Guys for the Help.

I used Ryan's code and works beautifully !!

Cheers

GREGS :)
 
Upvote 0

Forum statistics

Threads
1,214,492
Messages
6,119,868
Members
448,923
Latest member
emle1976

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