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 auto populate date in cell when adjacent cell is updated in Excel?

Sometimes, when update a cell in a certain column, you may want to mark the latest date about the updating. This article will recommend a VBA method to solve this problem. When cell is updated, the adjacent cell will be auto populated with current date immediately.

Auto populate current date in cell when adjacent cell is updated with VBA code


Combine multiple worksheets/workbooks into one worksheet / workbook:

Combine multiple worksheets or workbooks into one single worksheet or workbook may be a huge task in your daily work. But, if you have Kutools for Excel, its powerful utility – Combine can help you quickly combine multiple worksheets, workbooks into one worksheet or workbook

Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download the free trial Now!

Excel Productivity Tools

Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial

Kutools for Excel: Save 70% of your time and solve 80% Excel problems for you. 300+ advanced features designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial


Auto populate current date in cell when adjacent cell is updated with VBA code


Supposing the data you need to update locates in column B, and when cell in column B is updated, the current date will be populated in the adjacent cell of column A. See screenshot:

You can run the following VBA code to solve this problem.

1. Right click the sheet tab you need to auto populate date based on the adjacent updated cell, and then click View Code from the right-clicking menu.

2. In the Microsoft Visual Basic for Applications window, please copy and paste the below VBA code into the Code window.

VBA code: auto populate current date in a cell when the adjacent cell is updated

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Updated by Extendoffice 2017/10/12
    Dim xRg As Range, xCell As Range
    On Error Resume Next
    If (Target.Count = 1) Then
        If (Not Application.Intersect(Target, Me.Range("B:B")) Is Nothing) Then _
            Target.Offset(0, -1) = Date
        Application.EnableEvents = False
        Set xRg = Application.Intersect(Target.Dependents, Me.Range("B:B"))
        If (Not xRg Is Nothing) Then
            For Each xCell In xRg
                xCell.Offset(0, -1) = Date
            Next
        End If
        Application.EnableEvents = True
    End If
End Sub

Notes:

1. In the code, B:B means that the updated data locates in column B.

2. -1 indicates that the current date will be populated on the left one column of column B. If you want the current date populates in column C, please change -1 to 1.

3. Press Alt + Q keys at the same time to close the Microsoft Visual Basic for Applications window.

From now on, when updating cells in column B, the adjacent cell in column A will be populated with current date immediately. See screenshot:


Related articles:


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, 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 80% 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.
    Gwen · 2 months ago
    Hi. I'm trying to use the "Auto Populate Current Date In Cell When Adjacent Cell Is Updated With VBA Code". This works on Sheet 1, but I have 11 other sheets I need the code to work on. Please advise. I'm not VBA saavy at all so I appreciate any help I can get!

    Thanks.
    • To post as a guest, your comment is unpublished.
      crystal · 2 months ago
      Hi Gwen,
      Please repeat the steps to copy the code to other sheets. It may be tedious, but it works.
  • To post as a guest, your comment is unpublished.
    Tracey · 4 months ago
    I used this code to auto populate a column and now wish to auto populate more columns based on date entered into column H. In other words, once a date is entered can I auto populate columns to add date 90, 60, and 30 days out?
    • To post as a guest, your comment is unpublished.
      crystal · 3 months ago
      Hi Tracey,
      The following VBA code can help you solve the probem. Please have a try.

      Private Sub Worksheet_Change(ByVal Target As Excel.Range)
      Dim xRg As Range, xCell As Range
      Dim xRgAddress As String
      xRgAddress = "H:H"
      On Error Resume Next
      If (Target.count = 1) Then
      If (Not Application.Intersect(Target, Me.Range(xRgAddress)) Is Nothing) Then
      Target.Offset(0, 1) = Date + 90
      Target.Offset(0, 2) = Date + 60
      Target.Offset(0, 3) = Date + 30
      End If
      Application.EnableEvents = False
      Set xRg = Application.Intersect(Target.Dependents, Me.Range(xRgAddress))
      If (Not xRg Is Nothing) Then
      For Each xCell In xRg
      xCell.Offset(0, 1) = Date + 90
      xCell.Offset(0, 2) = Date + 60
      xCell.Offset(0, 3) = Date + 30
      Next
      End If
      Application.EnableEvents = True
      End If
      End Sub
  • To post as a guest, your comment is unpublished.
    Jen · 1 years ago
    Nevermind...I tried John's response below and it works - thank you!
  • To post as a guest, your comment is unpublished.
    Jen · 1 years ago
    HI - new to VBA - I want to loop the code - VBA code: auto populate current date in a cell when the adjacent cell is updated so that after a cell is updated with a date, then move on to say "J:J" and update K with date and then do 2 more times. Not sure if it is a loop or for? Thank you
  • To post as a guest, your comment is unpublished.
    sri laqshya · 1 years ago
    Hi,

    Can anyone one suggest a code for when I input number in column A and Column B and in Column C I kept a formula like Column A + Column B. Now I need a vba code that can give time and date in Column D whenever Column C changes not when inserting numbers in Column A and B.