ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Input Date when data is entered into another cell (https://www.excelbanter.com/excel-worksheet-functions/10892-input-date-when-data-entered-into-another-cell.html)

GaryByrd

Input Date when data is entered into another cell
 
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.

Otto Moehrbach

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
"GaryByrd" wrote in message
...
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.




Gord Dibben

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

On Mon, 31 Jan 2005 14:57:03 -0800, "GaryByrd"
wrote:

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.




All times are GMT +1. The time now is 10:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com