+ Reply to Thread
Results 1 to 4 of 4

Thread: Automatic Recording of current time when Specific Cell is Changed

  1. #1
    Registered User
    Join Date
    11-13-2009
    Location
    Horsfield Bay, Australia
    MS-Off Ver
    Excel 2007
    Posts
    32

    Automatic Recording of current time when Specific Cell is Changed

    Hey Guys
    I'm hoping you can assist me with a Macro. I have absolutely NO experience with Macro's so if you can give me as much help as possible that would be great.

    In regards to the attached document, I would like the cells in Row 3 to record the time when the cells in Row 4 are changed. For example, when "1000" is entered into cell B5 at 10:00pm, I want B3 to change to "22:00". When C5 changes, C3 with show the time of change. So if there is a way to have this for each of the columns B:H.

    Also, I would like a time of finish inserted into Row 40. So when the Value in Cell 39 changes from "NO" to "YES", I would like the cell underneath in Row 40 to show the time that change happens.

    If anyone could provide me with a Macro to help me with this, I would appreciate it. Also, if you could give me any information/instruction on how to use the Macro that would be fantastic. Thank you for all your help!

    Regards,
    Regan
    Attached Files Attached Files

  2. #2
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Automatic Recording of current time when Specific Cell is Changed

    Try this,

    Right Click the tab "Joes Sheet" then click View Code.

    In the resulting window paste all of this code

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim isect As Range
        
        Application.EnableEvents = False
        
        On Error GoTo ExitLine
        
        Set isect = Intersect(Target, Range("B5:H5"))
        If Not isect Is Nothing Then
            If Target = "" Then
                Target.Offset(-2, 0) = ""
            Else
                Target.Offset(-2, 0) = Format(Now(), "hh:mm")
            End If
        End If
        
        Set isect = Intersect(Target, Range("B39:H39"))
        If Not isect Is Nothing Then
            Target.Offset(1, 0) = Format(Now(), "hh:mm")
        End If
        
        Set isect = Nothing
        
    ExitLine:
        Application.EnableEvents = True
        On Error GoTo 0
    End Sub

    Hope this helps

    If you need any further information, please feel free to ask further

    However

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.
    Last edited by Marcol; 04-26-2010 at 06:29 AM. Reason: Added Dons' comment to code

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: Automatic Recording of current time when Specific Cell is Changed

    Marcol, I confess I've not read the question but I would make the point that though not vital in this instance (in terms of avoiding perpetual loop) you should toggle events when altering active sheet content via the Change event

    (ie the act of altering content will in turn re-invoke the change event - needlessly in this instance however were the altered cell within the range of interest you would end up in a perpetual loop).

    And if you toggle events you should add an error handler "just in case" so as to ensure events are reactivated irrespective of outcome.
    Last edited by DonkeyOte; 04-26-2010 at 06:11 AM. Reason: removed edit - misread code :oops:

  4. #4
    Forum Guru Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    5,590

    Re: Automatic Recording of current time when Specific Cell is Changed

    Hi Don,

    Point taken, I'm working on a time limited machine at the moment,( I'm away from home)
    To much a of a rush agianst available time.

    I've amended the code in Post #2

    Don't think it needs an error handler, but will check later.

    EDIT

    Okay, still in a rush, I've added belt and braces version

    Cheers
    Last edited by Marcol; 04-26-2010 at 06:26 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0