Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to update or insert (current) date and time by a Command Button in Excel?

Normally, many Excel users tend to insert timestamp with the formula =NOW(). With this formula, the inserted timestamp will be update automatically every time you open the workbook. For manually updating date and time in a worksheet at any time, how to achieve it? This article will show you method of updating current date and time by clicking a Command Button in Excel.

Update date and time by a Command Button with VBA code


Date picker (easily select date with specific date format from calendar)

Click Kutools  > Insert > Insert Date, and in the Insert Date dialog box, specify a date format, double click a certain date to insert this date into a selected cell immeidately. See screenshot below:

Kutools for Excel includes more than 300 handy Excel tools. Free to try with no limitation in 60 days. Download the free trial now


arrow blue right bubble Update date and time by a Command Button with VBA code


Please do as follows to update date and time by a Command Button in Excel.

1. Insert a Command Button by clicking Developer > Insert > Command Button (ActiveX Control). See screenshot:

2. Right click the inserted Command Button, then click View Code from the right-clicking menu.

3. In the popping up Microsoft Visual Basic for Applications window, please replace the original code with the below VBA code.

VBA code: Update date and time by a Command Button in Excel

Private Sub CommandButton1_Click()
    Range("A2").Value = Now()
End Sub

Note: In the code, CommandButton1 is the name of your inserted Command Button. And A2 is the cell which the update date and time will be displayed. Please change them as you need.

4. Turn off the Design Mode under the Developer tab. Click on the Command Button, then current date and time is inserted into cell A2.

And every time when you click on the Command Button, the date and time in cell A2 will be updated immediately.


arrow blue right bubbleRelated articles:


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    raph · 4 months ago
    Awesome! Thanks for this tutorial.


    However, how do i insert ONLY the date in DD/MM/YYYY format?
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      Hi,
      You can format the output cell as Short Date formatting to solve the problem.
  • To post as a guest, your comment is unpublished.
    joe higham · 7 months ago
    Hi there.. this is really good basic info..


    One question - how do you modify the code to put the datestamp into the NEXT row below, each time the button is pressed? (keeping the data previously written above?)


    Thank you so much!
    • To post as a guest, your comment is unpublished.
      crystal · 6 months ago
      Hi,
      The below VBA code will work on selected cell. When you want to insert timestampe to a cell, just select it and press the button.

      Private Sub CommandButton1_Click()
      Dim xRg As Range
      On Error Resume Next
      Set xRg = Selection
      xRg.Value = Now()
      End Sub