Logging an update

H

Howard

The other day some real great people gave me some code to enter "NOW" in a
cell when the cell is double clicked. It kind of works, but not exactly like
I need. I need for the code to insert the current date and time in cell $A$1
when the cell is double clicked, regardless of what is already in that cell.
The code is put in the Workbook module because it effects more than one
sheet. The code I have follows:

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target _
As Range, Cancel As Boolean)
If Target.Address = "$A$1" And Target.Value<>"" Then
Target.Value = Format(Now, "mm/dd/yyyy hh:mm:ss")
End If
Cancel = True
End Sub

This seems to work the first time the cell is double clicked, but after
that, it won't change the information. The "NOW" information is used to show
that last time the page was updated, and it may be changed more than once.

Any suggestions?
Thanks everyone,
 
D

Dave Peterson

You're checking two conditions. That A1 is the cell that you're doubleclicking
in and that it's empty to start.

If Target.Address = "$A$1" And Target.Value<>"" Then

If you don't want to check for emptyness:

If Target.Address = "$A$1" Then
 
J

John

Hi Howard

If you replace this line
If Target.Address = "$A$1" And Target.Value <> "" Then
With this:
If Target.Address = "$A$1" Then
Remove ( and Target.Value<>"")
It will print time & Date even if the cell is empty.
HTH
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top