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!


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:


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
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.
    Abbey · 12 days ago
    Hello, Can I set the date and the time to populate?
  • To post as a guest, your comment is unpublished.
    Joe · 3 months ago
    Hello, I need some help. I am trying to populate the current date into column A if any cells B through N are modified. The offset is throwing me off. Can this code be written to auto populate the date in Column A specifically?
  • To post as a guest, your comment is unpublished.
    Gwen · 7 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 · 6 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 · 8 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 · 7 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.
  • To post as a guest, your comment is unpublished.
    Sarah · 1 years ago
    Are you able to use this function twice on the same sheet? i.e. if I would like to make entries in column B to time stamp column A AND put entries in column D to timestamp column C. Thanks!
    • To post as a guest, your comment is unpublished.
      John · 1 years ago
      I got this to work by doing the following:


      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


      On Error Resume Next
      If (Target.Count = 1) Then
      If (Not Application.Intersect(Target, Me.Range("D:D")) Is Nothing) Then _
      Target.Offset(0, -1) = Date
      Application.EnableEvents = False
      Set xRg = Application.Intersect(Target.Dependents, Me.Range("D:D"))
      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
  • To post as a guest, your comment is unpublished.
    Michael · 1 years ago
    Thanks it works fine, but when it comes to close and save I'm getting a error that the feature "VB project" cannot be saved in a macro-free workbook. Please advise
    • To post as a guest, your comment is unpublished.
      Jay · 1 years ago
      You just need to "save as" a excel macro-enabled workbook....
  • To post as a guest, your comment is unpublished.
    Michael · 1 years ago
    Thanks it works fine, but when it comes to close and save I'm getting a error that the feature "VB project" cannot be saved in a macro-free workbook. Please advise
  • To post as a guest, your comment is unpublished.
    Tammy · 2 years ago
    Can this be accomplished on a cell that contains a formula?
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Tammy,
      The code has been updated. It can be accomplished on a cell that contains a formula now. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    leah · 2 years ago
    I have a set of excel worksheets titled monday, tuesday, wednesday, etc. I need to put the beginning date on Monday in cell a1, and have it fill in the subsequent dates for tuesday through Friday in cell a1 on each of those sheets. I am not code literate at all, so I just need to know what the simple formula I can put in there is. :) thank you!
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear leah,
      You just have to use the formula =monday!A1+1 on sheet tuesday, =tuesday!A1+1 on sheet wednesday and so on...
  • To post as a guest, your comment is unpublished.
    Jishnu · 2 years ago
    Thank You. This helped a lot.
    But when I am deleting a row or adding a row this gives an Run-time error 13 Type mismatch.

    How to tackle this issue.

    Expecting a revert ASAP.
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Dear Jishnu,
      The problem you mentioned does not appear in my case. Would you please provide your Office version?