View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Date Stamp in one cell when data in other range changes

maybe...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

Dim DateTimeCell As Range
Dim OldValCell As Range
Dim OldVal As Variant
Dim CurValue As String

With Target
If .Count 1 Then Exit Sub
If Not Intersect(Me.Range("H2:i150"), .Cells) Is Nothing Then
Set DateTimeCell = Me.Cells(.Row, "Q")
Set OldValCell = .Offset(0, 10)
CurValue = .Value

With Application
.EnableEvents = False
.Undo
End With

OldVal = .Value
.Value = CurValue

With DateTimeCell
.NumberFormat = "dd/mm hh:mm"
.Value = Now
End With

OldValCell.Value = OldVal
Application.EnableEvents = True
End If
End With
End Sub

RMF wrote:

Thnks dave,

I cannot make it do what I want however. I have two colums (H2:H150) and
(I2:I150). The first thing I want is that whenever I make a change in one of
the cells in these two ranges, the cell in the same row to be time stamped.
(e.g. I make a change in cell H15 so the cell in Q15 should be stamped. if i
make a change in cell I15 also Q15 should be stamped.

Secondly, I want the old value in the cell to be put in another cell. (e.g.
If i make a change in H15 I want the old value in R15 and if I make a change
to I15 I want the old value in S15).

Can anyone help me with this? Thnks a lot in advance!

RMF

p.s.
The code I use until now is this:
====================
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Range("H2:H150"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 24).ClearContents
Else
With .Offset(0, 24)
.NumberFormat = "dd/mm hh:mm"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
End With
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Range("I2:I150"), .Cells) Is Nothing Then
Application.EnableEvents = False
If IsEmpty(.Value) Then
.Offset(0, 24).ClearContents
Else
With .Offset(0, 24)
.NumberFormat = "dd/mm hh:mm"
.Value = Now
End With
End If
Application.EnableEvents = True
End If
=============================

"Dave Peterson" wrote:

Maybe...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Count 1 Then Exit Sub
If Not Intersect(Me.Range("C18:V32,C37:D43"), .Cells) Is Nothing Then
Application.EnableEvents = False
Me.Unprotect Password:="Hi"
With Me.Range("D1")
'move the old value over one column (to E1)
.Offset(0, 1).Value = .Value
.NumberFormat = "dd mmm yyyy hh:mm:ss"
.Value = Now
End With
Me.Protect Password:="Hi"
Application.EnableEvents = True
End If
End With
End Sub




RMF wrote:

Goodday,

I have used the macro on http://www.mcgimpsey.com/excel/timestamp.htm and
it works fine. I only would like to add something. When I make a change to a
cell, I want the time of the update in 1 cell but I also would like to have
the old value in another cell.

Can anyone help me with how I can do this? I am not too good with this VBA.

Thnks!




--

Dave Peterson