+ Reply to Thread
Results 1 to 2 of 2

Thread: run a macro if a certain cell value changed

  1. #1
    Registered User
    Join Date
    06-27-2011
    Location
    srilanka
    MS-Off Ver
    Excel 2007
    Posts
    3

    run a macro if a certain cell value changed

    hi
    i have wrote following code for get the last modified date of a cell.but the problem is whenever i double click on that cell it changes the date.but i want this macro to run if i changed existing value only.
    please help on this.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Count > 1 Then Exit Sub
        If Target.Column <> 5 Then Exit Sub
    
        Target.Offset(0, 1) = Now
        
    
    End Sub

  2. #2
    Forum Guru TMShucks's Avatar
    Join Date
    07-15-2010
    Location
    Manchester, England
    MS-Off Ver
    MSO 2003 & 2007
    Posts
    6,228

    Re: run a macro if a certain cell value changed

    Doble clicking only selects the cell for editing. If you press cancel, it won't put anything in.

    You can avoid the issue by including a further check:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Target.Count > 1 Then Exit Sub
        If Target.Column <> 5 Then Exit Sub
        If Target.Value = "" Then Exit Sub
    
        Target.Offset(0, 1) = Now
    
    End Sub

    Regards

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