Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding date to cell

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i have this fintion that displays the current date in a field if another cell is not empty..

=IF($A2<>"", NOW(),"")

works ok, however if i open the file tomorrow and update another row, the new date is ok but the old date changes..

how can i fix this??

many thanks,

Brian
 


Brian,

There is a sheet formula that I don't care to use, probably someone will post.

I much prefer a VBA (macro) using the Worksheet_Change event. This can be pasted in the Sheet Object code window, by right-click the sheet tab, select View Code
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'adds a date to column AA rather than
'=IF($A2<>"", NOW(),"")
    Dim COL As String
'CHANGE THIS for your column
    COL = "AA"

    If Target.Count > 1 Then Exit Sub
    
    If Target.Column = 1 Then
        With Cells(Target.Row, COL)
            .Value = Now
            .NumberFormat = "yyyy-mm-dd hh:mm"
        End With
    End If

End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top