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
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

manrav

New Member
Joined
Aug 19, 2002
Messages
14
try now()
you can use the now() function in a cell and then link the text box to that cell
 

manrav

New Member
Joined
Aug 19, 2002
Messages
14
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
 

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700

ADVERTISEMENT

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...
 

razzandy

Active Member
Joined
Jun 26, 2002
Messages
388
Office Version
  1. 2007
Platform
  1. Windows
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 :)
 

NateO

Legend
Joined
Feb 17, 2002
Messages
9,700
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
 

Gregs

Board Regular
Joined
Sep 6, 2002
Messages
96
Thanks Guys for the Help.

I used Ryan's code and works beautifully !!

Cheers

GREGS :)
 

Watch MrExcel Video

Forum statistics

Threads
1,123,124
Messages
5,599,839
Members
414,342
Latest member
K Darrell Smith

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
Top