简体   繁体   中英

Update Date automatically when I log data

I have been filling out an excel sheet logging project information. I would like to know how to have to populate a cell with the current date when I update cells in the adjacent row in the same sheet. There is currently information in the adjacent cells but I want it to hold the date that I previously updated it with. Only when I update the information I want it to change

I have googled for logical operator information but I cannot seem to find a direct answer. If there is a VB macro I could I am open to any solutions. I have found information on the TODAY() function in excel as well but I do not know how to apply it my particular problem. Any references to VB macros or information would be helpful. Thank you.

Try this, Alt-F11 to launch the editor, right-click "Sheet1" (or your sheet name) and select add code, paste in something like this:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim KeyCells As Range

    Set KeyCells = Range("B2:B10")

    If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
        Cells(Target.Row, Target.Column - 1) = Now()
    End If
End Sub

If you type something into B2 to B10 then the adjacent column is updated with the current date.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM