+ Reply to Thread
Results 1 to 4 of 4

Auto date stamp

Hybrid View

  1. #1
    Registered User
    Join Date
    02-24-2007
    Posts
    84

    Auto date stamp

    Hi All,

    Just a simple question, I'm using the following code (gained from a search on this forum) to great effect on a spreadsheet.

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        With Target
            If .Count > 1 Then Exit Sub
                'Update date-time stamp when a job is set in column A
                If Not Intersect(Range("a3:a200"), .Cells) Is Nothing Then
                    Application.EnableEvents = False
                    If IsEmpty(.Value) Then
                        .Offset(0, 4).ClearContents
                    Else
                        If .Offset(0, 11).Value = "" Then
                        With .Offset(0, 11)
                            .NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
                            .Value = Now
                        End With
                        End If
                    End If
                    Application.EnableEvents = True
                   
                'Update date-time stamp when job is completed in column I
                ElseIf Not Intersect(Range("i3:i200"), .Cells) Is Nothing Then
                    Application.EnableEvents = False
                    If IsEmpty(.Value) Then
                        .Offset(0, 3).ClearContents
                        .Offset(0, 4).ClearContents
                    Else
                        With .Offset(0, 4)
                            .NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
                            .Value = Now
                        End With
                        'Calculate job duration in column N
                        .Offset(0, 5).NumberFormat = "hh:mm:ss"
                        .Offset(0, 5) = .Offset(0, 4) - .Offset(0, 3)
                    End If
                Application.EnableEvents = True
            End If
        End With
    End Sub
    What I'd like to do now is add another auto date/time stamp into the routine so that an entry in column H triggers it.

    I tried copying the first routine (for column A) but get an error.
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        With Target
            If .Count > 1 Then Exit Sub
                'Update date-time stamp when a job is set in column A
                If Not Intersect(Range("a3:a200"), .Cells) Is Nothing Then
                    Application.EnableEvents = False
                    If IsEmpty(.Value) Then
                        .Offset(0, 4).ClearContents
                    Else
                        If .Offset(0, 11).Value = "" Then
                        With .Offset(0, 11)
                            .NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
                            .Value = Now
                        End With
                        End If
                    End If
                    Application.EnableEvents = True
    
                 'Update date-time stamp when a job is set in column H
                If Not Intersect(Range("h3:h200"), .Cells) Is Nothing Then
                    Application.EnableEvents = False
                    If IsEmpty(.Value) Then
                        .Offset(0, 4).ClearContents
                    Else
                        If .Offset(0, 7).Value = "" Then
                        With .Offset(0, 7)
                            .NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
                            .Value = Now
                        End With
                        End If
                    End If
                    Application.EnableEvents = True
                   
                'Update date-time stamp when job is completed in column I
                ElseIf Not Intersect(Range("i3:i200"), .Cells) Is Nothing Then
                    Application.EnableEvents = False
                    If IsEmpty(.Value) Then
                        .Offset(0, 3).ClearContents
                        .Offset(0, 4).ClearContents
                    Else
                        With .Offset(0, 4)
                            .NumberFormat = "dd/mmm/yyyy - hh:mm:ss"
                            .Value = Now
                        End With
                        'Calculate job duration in column N
                        .Offset(0, 5).NumberFormat = "hh:mm:ss"
                        .Offset(0, 5) = .Offset(0, 4) - .Offset(0, 3)
                    End If
                Application.EnableEvents = True
            End If
        End With
    End Sub
    Am I best off using a completely separate piece of code, or can I insert another sub-routine into this one?

    Thanks,
    Gavin.

  2. #2
    Registered User
    Join Date
    02-24-2007
    Posts
    84
    Nobody got a suggestion?

    I'm surprised and still a little lost.

    Thanks anyway.
    Gavin.

  3. #3
    Valued Forum Contributor ratcat's Avatar
    Join Date
    03-07-2008
    Location
    Rural NSW, Australia
    MS-Off Ver
    Vista 2007
    Posts
    1,111
    Suggestion

    PM a Forum Mod to move this post to the Excel Programming Forum

    Or

    Re post in the Excel Programming Forum. If you do re post, please follow theExcel Forum Site Rules.

    Cheers
    Have I made you happy ??? If yes, please make me happy by pressing the http://www.excelforum.com/images/buttons/reputation-40b.png Add Reputation button in my post.
    Please don't forget to do the same to other contributors of this forum.

    Thanks
    I don't void confusion, I create it

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    You don't say what your error is, but try changing the if statement for column H to and elseif.

    If this does not solve the problem then explain the error and perhaps put up a sample file, and what steps you take to generate the error.

    rylo
    Last edited by rylo; 05-13-2008 at 02:04 AM.

+ 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