• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to get the difference between two timestamps

miming1986

New Member
Hi,

I'm just starting to learn VBA. Can you help with the codes I need to use so column L (starting from L3) will auto-calculate (L3-C3) and so on and so forth.

Currently I have codes on my worksheet to automatically create timestamps based on data entered on columns B and J and column L should need to calculate the difference of the two. Is it also possible if the results on column L are in decimal format to two decimal places?

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    Dim rCell As Range
    Dim rChange As Range
  
    On Error GoTo ErrHandler
    Set rChange = Intersect(Target, Range("B:B,J:J"))
    If Not rChange Is Nothing Then
        Application.EnableEvents = False
        For Each rCell In rChange
            If rCell > "" Then
                With rCell.Offset(0, 1)
                    .Value = Now
                    .NumberFormat = "hh:mm:ss"
                End With
            Else
                rCell.Offset(0, 1).Clear
            End If
        Next
    End If

ExitHandler:
    Set rCell = Nothing
    Set rChange = Nothing
    Application.EnableEvents = True
    Exit Sub
ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler
End Sub

Thanks so much. I would really appreciate your responses.
 

Attachments

  • upload_2017-3-22_14-19-0.png
    upload_2017-3-22_14-19-0.png
    23.2 KB · Views: 33
Last edited:
@miming1986
Last time You wanted:
I don't want previous time to update especially when they update values on columns B or anything that prevents them from manipulating the data.
... and now You would them manipulate the data.
> case L-col ... change columns format to two decimals
 
Back
Top