+ Reply to Thread
Results 1 to 3 of 3

Removing time in cell

Hybrid View

  1. #1
    Registered User
    Join Date
    05-07-2009
    Location
    England
    MS-Off Ver
    Excel 2000
    Posts
    22

    Removing time in cell

    Hi everyone,

    I have some code that display date and time in a cell when "done" is input into the adjaecent cell. (Any value would be the trigger, though)

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    
    If Target.Cells.Count = 1 And Target.Column = 7 Then
    Target.Offset(0, 1) = Now
    
    End If
    End Sub
    Can this be altered so that when "done" is deleted in the adjaecent cell the time/date is removed. At the moment you have to do it manually.

    Thanks in advance
    Last edited by bigbadlee; 05-16-2009 at 05:09 PM. Reason: solved

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Removing time in cell

    Hello bigbadlee,

    This will recognize only "Done" in the cell. It is not case sensitive. Any other value will clear the adjacent cell. To prevent a cascade failure, I have added Application.EnableEvents to the macro. This will prevent the macro from calling itself over, and over when the cell value is changed.
    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    
    Application.EnableEvents = False
    If Target.Cells.Count = 1 And Target.Column = 7 Then
      Select Case LCase(Target.Value)
        Case "done"
          Target.Offset(0, 1) = Now()
        Case Else
          Target.Offset(0, 1) = ""
      End Select
    End If
    Application.EnableEvents = True
    
    End Sub
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-07-2009
    Location
    England
    MS-Off Ver
    Excel 2000
    Posts
    22

    Thumbs up Re: Removing time in cell

    Hi Leith,

    Absolutely fantastic.

    Thank you very much for your swift reply

+ 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