Input Date when data is entered into another cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to use Excel sorta like a database. When I enter data into a cell
such as B1 I want A1 to stamp the date and time.
 
Gary
You'll need an event macro to do that. Something like:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Or Target = "" Then Exit Sub
If Target.Column = 2 Then Target.Offset(, -1) = Now
End Sub

Watch out for line wrap in this message. Expand this message to see the
code properly. Right-click on the sheet tab, select View Code, and paste
this macro in that module. HTH Otto
 
Gary

Copy/paste the following into a worksheet module. Right-click on the sheet
tab and "View Code". Paste in there. Format Column A to Time.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'when entering data in Col B
On Error GoTo enditall
Application.EnableEvents = False
If Target.Cells.Column = 2 Then 'can be modified, see below
n = Target.row
If Excel.Range("B" & n).Value <> "" Then
Excel.Range("A" & n).Value = Now
End If
End If
enditall:
Application.EnableEvents = True
End Sub

As written, operates on all of column B.

'For one cell use
'If Target.Address = "$B$1" Then
'''
'For a range use
'If Not Application.Intersect(Range("B1:B20"), Target) Is Nothing Then


Gord Dibben Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top