ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code modification help (https://www.excelbanter.com/excel-programming/423659-code-modification-help.html)

AndyMP

Code modification help
 
I found this code on the web for updating a cell with the time and date
whenever a specified range of cells is edited. In order to do this it is
using the Worksheet_change function. The code prints the time and date in the
cell beside the one that is changed. What I would like to do is have the time
and date printed in one, single specific cell. Can this be done ?

Here is the code....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Range("A2:A10"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub


Don Guillett

Code modification help
 
Without rewriting the whole thing, change
With .Offset(0, 1)
to
with range("c12")


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"AndyMP" wrote in message
...
I found this code on the web for updating a cell with the time and date
whenever a specified range of cells is edited. In order to do this it is
using the Worksheet_change function. The code prints the time and date in
the
cell beside the one that is changed. What I would like to do is have the
time
and date printed in one, single specific cell. Can this be done ?

Here is the code....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Range("A2:A10"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub



AndyMP

Code modification help
 
Sorry for the double post, I got an error when posting and that's why I
posted twice. Anyway, this solution works perfectly. Thank You !

"Don Guillett" wrote:

Without rewriting the whole thing, change
With .Offset(0, 1)
to
with range("c12")


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"AndyMP" wrote in message
...
I found this code on the web for updating a cell with the time and date
whenever a specified range of cells is edited. In order to do this it is
using the Worksheet_change function. The code prints the time and date in
the
cell beside the one that is changed. What I would like to do is have the
time
and date printed in one, single specific cell. Can this be done ?

Here is the code....

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Range("A2:A10"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 1).ClearContents
Else
With .Offset(0, 1)
.NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
End Sub





All times are GMT +1. The time now is 02:58 PM.

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