+ Reply to Thread
Results 1 to 4 of 4

Auto-Run Macro when Cell Value Changes

Hybrid View

  1. #1
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Auto-Run Macro when Cell Value Changes

    Dear all, I understand this subject has been mentioned many times across the forums and I've tried searching for a solution that could work but perhaps I am missing something in the codes that I've put up.

    What I am trying to do is to run a particular case of macro when a certain value is entered into a cell.

    E.g. When Cell A1 shows 1 , auto run MacroDate_1
    When Cell A2 shows 2 , auto run MacroDate_2

    and this pretty much goes on until 31. Below are the codes that I've found and modified so far. I've attached it to the 'Sheets' but nothing happens. Apologies as I am not able to send a spreadsheet on this.

    Thanks in advance for taking a look at this.

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
        If Target.Address = "$E$6" Then
            Select Case Target.Value
            Case 1: MacroDate_1
            Case 2: MacroDate_2
            Case 3: MacroDate_3
            Case 4: MacroDate_4
            Case 5: MacroDate_5
            Case 6: MacroDate_6
            Case 7: MacroDate_7
            Case 8: MacroDate_8
            Case 9: MacroDate_9
            Case 10: MacroDate_10
            Case 11: MacroDate_11
            Case 12: MacroDate_12
            Case 13: MacroDate_13
            Case 14: MacroDate_14
            Case 15: MacroDate_15
            Case 16: MacroDate_16
            Case 17: MacroDate_17
            Case 18: MacroDate_18
            Case 19: MacroDate_19
            Case 20: MacroDate_20
            Case 21: MacroDate_21
            Case 22: MacroDate_22
            Case 23: MacroDate_23
            Case 24: MacroDate_24
            Case 25: MacroDate_25
            Case 26: MacroDate_26
            Case 27: MacroDate_27
            Case 28: MacroDate_28
            Case 29: MacroDate_29
            Case 30: MacroDate_30
            Case 31: MacroDate_31
            Case Else ' do nothing
            End Select
        End If
    End Sub

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Auto-Run Macro when Cell Value Changes

    Maybe: (per your e.g.)

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A1:A31")) Is Nothing Then
        Select Case Target.Value
        Case Is = 1
            If Target.Address = "$A$1" Then Call MacroDate_1
        Case Is = 2
            If Target.Address = "$A$2" Then Call MacroDate_2
        Case Is = 3
            If Target.Address = "$A$3" Then Call MacroDate_3
        Case Is = 4
            If Target.Address = "$A$4" Then Call MacroDate_4
        Case Is = 5
            If Target.Address = "$A$5" Then Call MacroDate_5
        Case Is = 6
            If Target.Address = "$A$6" Then Call MacroDate_6
        Case Is = 7
            If Target.Address = "$A$7" Then Call MacroDate_7
        Case Is = 8
            If Target.Address = "$A$8" Then Call MacroDate_8
        Case Is = 9
            If Target.Address = "$A$9" Then Call MacroDate_9
        Case Is = 10
            If Target.Address = "$A$10" Then Call MacroDate_10
        Case Is = 11
            If Target.Address = "$A$11" Then Call MacroDate_11
        Case Is = 12
            If Target.Address = "$A$12" Then Call MacroDate_12
        Case Is = 13
            If Target.Address = "$A$13" Then Call MacroDate_13
        Case Is = 14
            If Target.Address = "$A$14" Then Call MacroDate_14
        Case Is = 15
            If Target.Address = "$A$15" Then Call MacroDate_15
        Case Is = 16
            If Target.Address = "$A$16" Then Call MacroDate_16
        Case Is = 17
            If Target.Address = "$A$17" Then Call MacroDate_17
        Case Is = 18
            If Target.Address = "$A$18" Then Call MacroDate_18
        Case Is = 19
            If Target.Address = "$A$19" Then Call MacroDate_19
        Case Is = 20
            If Target.Address = "$A$20" Then Call MacroDate_20
        Case Is = 21
            If Target.Address = "$A$21" Then Call MacroDate_21
        Case Is = 22
            If Target.Address = "$A$22" Then Call MacroDate_22
        Case Is = 23
            If Target.Address = "$A$23" Then Call MacroDate_23
        Case Is = 24
            If Target.Address = "$A$24" Then Call MacroDate_24
        Case Is = 25
            If Target.Address = "$A$25" Then Call MacroDate_25
        Case Is = 26
            If Target.Address = "$A$26" Then Call MacroDate_26
        Case Is = 27
            If Target.Address = "$A$27" Then Call MacroDate_27
        Case Is = 28
            If Target.Address = "$A$28" Then Call MacroDate_28
        Case Is = 29
            If Target.Address = "$A$29" Then Call MacroDate_29
        Case Is = 30
            If Target.Address = "$A$30" Then Call MacroDate_30
        Case Is = 31
            If Target.Address = "$A$31" Then Call MacroDate_31
        End Select
    End If
    End Sub

  3. #3
    Registered User
    Join Date
    10-12-2010
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: Auto-Run Macro when Cell Value Changes

    Hi John,

    Thanks for the reply ! Also realized why it was working was because the cell i was referring to is a formula and not actual values. Nevertheless thanks for the reply ! I went along this route instead

    If Range("E6").Value = "1" Then Call MacroDate_1
    If Range("E6").Value = "2" Then Call MacroDate_2
    If Range("E6").Value = "3" Then Call MacroDate_3
    If Range("E6").Value = "4" Then Call MacroDate_4
    If Range("E6").Value = "5" Then Call MacroDate_5
    If Range("E6").Value = "6" Then Call MacroDate_6
    If Range("E6").Value = "7" Then Call MacroDate_7
    If Range("E6").Value = "8" Then Call MacroDate_8
    If Range("E6").Value = "9" Then Call MacroDate_9
    If Range("E6").Value = "10" Then Call MacroDate_10
    If Range("E6").Value = "11" Then Call MacroDate_11
    If Range("E6").Value = "12" Then Call MacroDate_12
    If Range("E6").Value = "13" Then Call MacroDate_13
    If Range("E6").Value = "14" Then Call MacroDate_14
    If Range("E6").Value = "15" Then Call MacroDate_15
    If Range("E6").Value = "16" Then Call MacroDate_16
    If Range("E6").Value = "17" Then Call MacroDate_17
    If Range("E6").Value = "18" Then Call MacroDate_18
    If Range("E6").Value = "19" Then Call MacroDate_19
    If Range("E6").Value = "20" Then Call MacroDate_20
    If Range("E6").Value = "21" Then Call MacroDate_21
    If Range("E6").Value = "22" Then Call MacroDate_22
    If Range("E6").Value = "23" Then Call MacroDate_23
    If Range("E6").Value = "24" Then Call MacroDate_24
    If Range("E6").Value = "25" Then Call MacroDate_25
    If Range("E6").Value = "26" Then Call MacroDate_26
    If Range("E6").Value = "27" Then Call MacroDate_27
    If Range("E6").Value = "28" Then Call MacroDate_28
    If Range("E6").Value = "29" Then Call MacroDate_29
    If Range("E6").Value = "30" Then Call MacroDate_30
    If Range("E6").Value = "31" Then Call MacroDate_31

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Auto-Run Macro when Cell Value Changes

    You're welcome. Glad you got a solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to auto select adjacent cell then cell underneath
    By strud in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-21-2013, 05:48 AM
  2. Auto run a macro when cell value changes
    By Tanya0806 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2013, 02:15 PM
  3. Replies: 0
    Last Post: 01-29-2013, 04:59 PM
  4. Replies: 2
    Last Post: 06-03-2012, 03:33 PM
  5. Macro to auto populate the destination cell based on the values of the previous cell
    By Avinash Kumar in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-05-2009, 02:06 AM

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