ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Time/Date Stamp Multiple Rows (https://www.excelbanter.com/excel-discussion-misc-queries/226086-time-date-stamp-multiple-rows.html)

DataGuy

Time/Date Stamp Multiple Rows
 
I am using the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("B16:F74")) Is Nothing Then
Range("G16:G74") = Now
Application.EnableEvents = True
End If
End Sub

I get the same time and date in all the rows. How can I fix my code so that
it is row specific.

Dave Peterson

Time/Date Stamp Multiple Rows
 
Maybe something like:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

Dim myRow As Long

If Target.Cells.Count 1 Then
Exit Sub 'one cell at a time
End If

If Application.Intersect(Target, Me.Range("B16:F74")) Is Nothing Then
'do nothing
Else
myRow = Target.Row
With Me.Cells(myRow, "G")
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
Application.EnableEvents = False
.Value = Now
Application.EnableEvents = True
End With
End If
End Sub


DataGuy wrote:

I am using the following code:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("B16:F74")) Is Nothing Then
Range("G16:G74") = Now
Application.EnableEvents = True
End If
End Sub

I get the same time and date in all the rows. How can I fix my code so that
it is row specific.


--

Dave Peterson


All times are GMT +1. The time now is 04:18 AM.

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