Consulting

Results 1 to 6 of 6

Thread: Execute Macro on Cell Change

  1. #1
    VBAX Regular
    Joined
    Dec 2012
    Posts
    35
    Location

    Execute Macro on Cell Change

    Hello,
    I've spent quite a bit of time researching this, but haven't found anything super helpful.

    Goal: Execute macro on cell value change.
    Current: Executes macro on target cell selection

    Any ideas? Happy Monday!

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
       
        If Target.Address = "$E$8:$G$8" Then
                Sheets("Account Details").Range("ExpirationDate").Formula = "=IF(E8="""","""",DATEVALUE(MONTH(E8)&"" / ""&DAY(E8)&"" / ""&(YEAR(E8)+1)))"
       End If
       
    End Sub

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi mikeoly!
    not sure, change "Worksheet_SelectionChange" to "Worksheet_Change" and try again.

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Private Sub Worksheet_Change(ByVal Target As Range)
       
        If Not Intersect(Target, Me.Range = "$E$8:$G$8") Is Nothing Then
            
            Worksheets("Account Details").Range("ExpirationDate").Formula = "=IF(E8="""","""",DATEVALUE(MONTH(E8)&"" / ""&DAY(E8)&"" / ""&(YEAR(E8)+1)))"
        End If
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Mentor
    Joined
    Dec 2008
    Posts
    404
    Location
    Quote Originally Posted by xld View Post
    (...)
        If Not Intersect(Target, Me.Range = "$E$8:$G$8") Is Nothing Then
        (...)
    It should be
    If Not Intersect(Target, Me.Range("$E$8:$G$8")) Is Nothing Then
    Artik

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,711
    Location
    Don't know about the formula, but I'd do

    Private Sub Worksheet_Change(ByVal Target As Range)
       
        If Intersect(Target, Range ("$E$8:$G$8") Is Nothing Then Exit Sub
            
        Worksheets("Account Details").Range("ExpirationDate").Formula = "=IF(E8="""","""",DATEVALUE(MONTH(E8)&"" / ""&DAY(E8)&"" / ""&(YEAR(E8)+1)))"
    
    End Sub
    
    
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Regular
    Joined
    Dec 2012
    Posts
    35
    Location
    Thanks all! A few of the suggestions seemed to work well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •