+ Reply to Thread
Results 1 to 7 of 7

Executing a VBA Macro using a change in a data validation cell as the trigger

  1. #1
    Registered User
    Join Date
    10-05-2015
    Location
    Michigan
    MS-Off Ver
    2013
    Posts
    11

    Executing a VBA Macro using a change in a data validation cell as the trigger



    Hi everyone,

    I would greatly appreciate your help to solve what should be a simple item but I have not found a solution in too many attempts, and now I think I am being moronic

    I have a cell located at g28 that I have named "RevModSel"

    There are 6 items in my data validation list with are:
    • Aggressive
    • Standard
    • Conservative
    • Roll Your Own
    • Splash a Number
    • Cell by Cell

    The fundamental macro I built to test my functions is as follows:

    Sub IF_Test()

    Select Case Range("RevModSel")
    Case "Aggressive"
    Range("result") = 1
    Case "Standard"
    Range("result") = 2
    Case "Conservative"
    Range("result") = 3
    Case "Roll Your Own"
    Range("result") = 4
    Case "Splash a Number"
    Range("result") = 5
    Case "Cell by Cell"
    Range("result") = 6
    End Select
    End Sub

    I have read many posts that indicate that I have to add something like the code below to trigger the macro on a change of the data validation result at "RevModSel" (cell G28)



    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "RevModSel" Then
    Call IF_Test
    End If
    End Sub

    However, the debugger keeps failing an I am not seeing or understanding why.

    Would someone please be so kind to modify the code above to help me get this working.

    Thanks,

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Executing a VBA Macro using a change in a data validation cell as the trigger

    Address won't return a name, it will return, well, an address.

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-05-2015
    Location
    Michigan
    MS-Off Ver
    2013
    Posts
    11

    Re: Executing a VBA Macro using a change in a data validation cell as the trigger

    Hi Norie,

    Nice try but I got a compile error: syntax error immediately turning this line yellow

    Private Sub Worksheet_Change(ByVal Target As Range)

    and the next line below is highlighted in blue

    If Not Intersect(Target Range("RevModSel")) Is Nothing Then

  4. #4
    Registered User
    Join Date
    10-05-2015
    Location
    Michigan
    MS-Off Ver
    2013
    Posts
    11

    Re: Executing a VBA Macro using a change in a data validation cell as the trigger

    Norie,

    Here is the excel formula that works.

    =IF(RevModSel=G22,1,IF(RevModSel=G23,2,IF(RevModSel=G24,3,IF(RevModSel=G25,4,IF(RevModSel=G26,5,IF(RevModSel=G27,6,7))))))


    The macro should work the same way this formula does

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Executing a VBA Macro using a change in a data validation cell as the trigger

    That's my fault, a typo.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-05-2015
    Location
    Michigan
    MS-Off Ver
    2013
    Posts
    11

    Re: Executing a VBA Macro using a change in a data validation cell as the trigger

    Thanks Norie, Yup the comma made a big difference. Works perfect Now I want to figure out why I was such a Moron

  7. #7
    Registered User
    Join Date
    10-05-2015
    Location
    Michigan
    MS-Off Ver
    2013
    Posts
    11

    Re: Executing a VBA Macro using a change in a data validation cell as the trigger

    Hi Norie,

    I now have another question. The code below works fine in debug (F5), however my expectation was that when the user enters a number in cell "B5" (named Enter_Shift) that the code would execute. Can you please tell me why it is not executing?

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("Enter_Shift")) Is Nothing Then
    Call checkInt
    End If
    End Sub


    Sub checkInt()

    If Range("Enter_Shift") > 0 And Range("Enter_Shift") < Range("Max_Shift") Then
    MsgBox "OK"
    Else
    MsgBox "Specified Shift is out of Range"
    End If

    End Sub

+ 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. Trigger Macro on cell change by real time data
    By boesingen in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-04-2013, 04:22 PM
  2. Change of value in a cell don't trigger macro
    By tuf82 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-01-2011, 09:50 AM
  3. Macro to trigger Data Validation
    By amdk8800 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-22-2010, 05:38 PM
  4. Trigger Macro on change in cell value
    By qwerty in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-26-2006, 12:30 AM
  5. [SOLVED] Executing macro on cell change.
    By Brad in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-15-2006, 06:10 AM
  6. [SOLVED] Cell value change to trigger macro (worksheet change event?)
    By Neil Goldwasser in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2006, 10:00 AM
  7. Cell Data Change to Trigger Macro
    By documike in forum Excel General
    Replies: 8
    Last Post: 01-06-2005, 03:06 PM

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