View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Ken Johnson Ken Johnson is offline
external usenet poster
 
Posts: 1,073
Default Macro to insert Now() when cell updates

Hi Rob,
Is what you are trying to do really going to overcome the problem of
each Now being updated or overwritten?. When you use VBA to place Now
in a cell it doesn't put the Now function into that cell it just puts
in the current Now value, ie a static date and time value. Each time
your code runs it will update the cell with the new Now value and you
lose the old one. If you don't want to lose any old Now values you will
need to use the Offset method to shift all the older Now values across
one column or down one row.
For example: when the following code is run it puts the current Now
value into B1 then shifts all previous Now values down one row by way
of the Offset method copying each value into the cell immediately
below. When the loop reaches B1 that too is copied into B2.

Public Sub SaveOldNows()
Range("B1").Value = Now
For iRowOffset = Application.Count(Range("B:B")) To 1 Step -1
'Shift old time values down 1 row
Let Cells(iRowOffset + 1, 2).Value = Cells(iRowOffset, 2).Value
Next iRowOffset
End Sub

Also, what is the effect of the "\"'s in your code. I've never seen
anything like it before?
<if range(\"f6:f45\") = \"1\" then

Also, in the first line of your code are you intending to detect if the
sheet change has occurred anywhere in the range F6:F45?
If that is the case then the way I have seen it done is...

If Intersect(Target,Range("F6:F45")) Is Nothing then
Exit Sub
End If

Hope this helps you.

Ken Johnson