Results 1 to 2 of 2

VBA code Time Stamp based on cell value

Threaded View

  1. #1
    Registered User
    Join Date
    03-18-2013
    Location
    london, England
    MS-Off Ver
    Excel 2010
    Posts
    2

    VBA code Time Stamp based on cell value

    Dear All,

    for the last 4 months or so i have been trying to write a vba code that would do the following :

    1. in cell D i have a value which generated by a formula in a different cell.
    if all conditions are met then the value in cell D =1 .
    2. if D=1 then i would like to have a time stamp each time the value is 1
    3. i have 4 Ranges with the same logic : D116:D220; D221:D320; M116:M220;M221:D320

    the question is this:
    manual entering 1 at the D116:D220 Range does give Date + Time at the relevant cells.
    using Worksheet_calculate ( the D=1 is by a calculation) does not give me the date+time is the relevant cells.

    this is the code i use. i got it from this board, if i remember correctly (many thanks to the poster) and made some changes to my needs.

    Private Sub Worksheet_Calculate()
    
        On Error GoTo Finish
        Application.EnableEvents = Flase
         
         'if more than one cell is selected, exit
        If Target.Cells.Count > 1 Then Exit Sub
         
         'if selected cell is in range D116 to D220
         ' If NOT Nothing, then is something!
        If Not Intersect(Target, Range("D116:D220")) Is Nothing Then
             'check if cell value is 1
            If Target.Value = "1" Then
                 'yes, put 'Time + Date' in cell that is offset from selected cell
                 ' by +0 rows, -3 column from selected cell
                 ' ie: same row, next column over
                Target.Offset(0, -3).Value = Time + Date
            Else
                 'value not 'x', put blank in next column, same row
                Target.Offset(0, -3).Value = ""
            End If
        End If
         
         'if cell is in range H18 to H117
        If Not Intersect(Target, Range("M116:M320")) Is Nothing Then
             'check if is '1'
            If Target.Value = 1 Then
                 'yes = put Date + Time 3 Coulmns back
                Target.Offset(0, -11).Value = Time + Date
            Else
                 'value not 'x', put blank in next column, same row
                Target.Offset(0, -11).Value = ""
            End If
        End If
         'if cell is in range I18 to I117
        If Not Intersect(Target, Range("D221:D320")) Is Nothing Then
             'check if is '1'
            If Target.Value = 1 Then
                 'yes = put Date + Time 3 Coulmns back
                Target.Offset(0, -3).Value = Time + Date
             Else
                 'value not '1', put blank in next column, same row
                Target.Offset(0, -3).Value = ""
            End If
        End If
    thanks in advance
    YodArbel
    Last edited by arlu1201; 03-19-2013 at 01:59 AM. Reason: Use code tags in future.

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