Datestamp adjacent cell to data input - 2 date columns on same sheet


Posted by Sid on July 20, 2001 6:05 AM

I have a list in the format

H I J K
Fitted By Date Fitted Removed By Date Removed

Cells in H & J are inputed by a data validation list. I want adjacent cells in I & K to have the current date inserted automatically.

I've been thro' the problem of Cell I2 =IF(NOT(H2=""),NOW(),"") being reset to the current date each time workbook is opened.

I have found this code on this most excel-lent messageboard, but can only get it to work for 1 column. Anybody know how to get it to work for both date columns

Private Sub Worksheet_Change(ByVal Target As Range)
Dim keyRange As Range
Set keyRange = Range("h:h")
If Not Intersect(keyRange, Target) Is Nothing Then
Target.Offset(0, 1) = Date
End If
End Sub


Thanx Sid

Posted by Ivan F Moala on July 20, 2001 6:57 AM

Try this ???
Private Sub Worksheet_Change(ByVal Target As Range)
Dim keyRange As Range

Set keyRange = Range("h2:h65536", "J2:J65336")
Application.EnableEvents = False

If Not Intersect(keyRange, Target) Is Nothing Then
If Target <> "" Then
Target.Offset(0, 1) = Date
Else
Target.Offset(0, 1) = ""
End If
End If
Application.EnableEvents = True
End Sub

Ivan



Posted by Sid on July 20, 2001 7:04 AM

Fantastic!
Many Thanx Ivan

: I have a list in the format : H I J K : Fitted By Date Fitted Removed By Date Removed : Cells in H & J are inputed by a data validation list. I want adjacent cells in I & K to have the current date inserted automatically. : I've been thro' the problem of Cell I2 =IF(NOT(H2=""),NOW(),"") being reset to the current date each time workbook is opened. : I have found this code on this most excel-lent messageboard, but can only get it to work for 1 column. Anybody know how to get it to work for both date columns : Private Sub Worksheet_Change(ByVal Target As Range) : Dim keyRange As Range : Set keyRange = Range("h:h") : If Not Intersect(keyRange, Target) Is Nothing Then : Target.Offset(0, 1) = Date : End If : End Sub : : Thanx Sid