+ Reply to Thread
Results 1 to 4 of 4

Macro inserts date based on cell value

Hybrid View

  1. #1
    Registered User
    Join Date
    03-22-2013
    Location
    Utah, United States
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro inserts date based on cell value

    Currently I have the following macro that inserts a date in a cell as soon as another cell is clicked.
    However I need it to only insert the date if the cell value is equal to COMPLETED.

    Current macro.
    
    private sub worksheet_selectionChange(byval target as range)
       If target.cells.count > 1 then exit sub
          If target.row > 1 and target column = 7 then
              Cells(target.row, "R") = Date
    End if
    
    End sub

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Macro inserts date based on cell value

    are you missing a . between target and column? that doesn't fix your issue just curious...
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Macro inserts date based on cell value

    Based upon your post it sounds to me like you would be better suiting using the Worksheet Change event instead of Worksheet SelectionChange

    tRY:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("G2:G" & Rows.Count)) Is Nothing Then
        If Target.Value = "COMPLETED" Then
            Range("R" & Target.Row).Value = Date
        End If
    End If
    
    End Sub

  4. #4
    Registered User
    Join Date
    03-22-2013
    Location
    Utah, United States
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro inserts date based on cell value

    Quote Originally Posted by stnkynts View Post
    Based upon your post it sounds to me like you would be better suiting using the Worksheet Change event instead of Worksheet SelectionChange

    tRY:

    
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("G2:G" & Rows.Count)) Is Nothing Then
        If Target.Value = "COMPLETED" Then
            Range("R" & Target.Row).Value = Date
        End If
    End If
    
    End Sub
    Works perfectly. Thanks,

+ 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.6.0 RC 1