+ Reply to Thread
Results 1 to 12 of 12

Date stamping a cell

Hybrid View

  1. #1
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Do this

    Right click sheet name > select view code > paste in the below code > Close VB editor

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
            With Target
                If .Count > 1 Then Exit Sub
                If Not Intersect(Range("D2"), .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
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  2. #2
    Registered User
    Join Date
    10-12-2007
    Posts
    13
    Thanks,

    but when i enter text I just get loads of #########

    The cells are formatted for dates.

  3. #3
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Widen the column

    VBA Noob

  4. #4
    Registered User
    Join Date
    10-12-2007
    Posts
    13
    brilliant, so can i copy that all the way down the sheet??

    thanks for this

  5. #5
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Change range on this line

    If Not Intersect(Range("D2"), .Cells) Is Nothing Then
    to either

    If Not Intersect(Range("D1:D65536"), .Cells) Is Nothing Then
    or

     If Not Intersect(Columns(4), .Cells) Is Nothing Then
    VBA Noob

  6. #6
    Registered User
    Join Date
    10-12-2007
    Posts
    13
    Thanks

    Works

  7. #7
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Glad it helped

    VBA Noob

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1