+ Reply to Thread
Results 1 to 16 of 16

Running A Macro When Any Validation List Item is Selected

  1. #1
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Running A Macro When Any Validation List Item is Selected

    I need to know what code I would need to insert into a Workbook tab (under "View Code") that would run a simple macro regardless of which item is selected in a validation list? The macro name is "UpdateDMReport"

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running A Macro When Any Validation List Item is Selected

    Try something like this. Change the A1 to the cell that has the DV list.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    Thx for the quick response! The validation list is at cell "C5"....I replaced "A1" with "C5" and nothing happens when you select any of the list choices. I am using Excel 2010...if that makes a difference. Thoughts?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running A Macro When Any Validation List Item is Selected

    Did you put the code in the worksheet code module (not the workbook code module)? Right-click on the worksheet tab and select View Code.

  5. #5
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    Yes...I right clicked on the worksheet tab, selected View Code, pasted the code in and changed A1 to C5. I am stumped.

    code.png

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running A Macro When Any Validation List Item is Selected

    Use "C5" and not "$c$5". It matters in this case.

  7. #7
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    I tried it both as "C5" and "$C$5" and neither worked. A created a button and assigned the macro to that button and it runs fine so the issue is not the macro.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running A Macro When Any Validation List Item is Selected

    Run this macro once to ensure the worksheet events are enabled.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    I ran the code and then tried the validation box...no change

  10. #10
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running A Macro When Any Validation List Item is Selected

    Did you put "C5" with a capital C?

    What is your code for UpdateDMReport ?

  11. #11
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    Here is the Macro Code...


    Sub UpdateDMReport()
    '
    ' UpdateDMReport Macro
    '

    '
    ' Stop screen changes (flickering) from being viewed

    Application.ScreenUpdating = False

    Sheets("Combined").Visible = True
    Sheets("Combined").Select
    Columns("AA:AU").Select
    Selection.Copy
    Columns("AY:AY").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("BW5").Select
    Application.CutCopyMode = False

    ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
    Range("BW502").Select

    ActiveSheet.PivotTables("PivotTable4").PivotCache.Refresh
    Range("BW803").Select

    ActiveSheet.PivotTables("PivotTable5").PivotCache.Refresh
    Sheets("Combined").Select
    ActiveWindow.SelectedSheets.Visible = False
    Sheets("DM View").Select
    Range("E14").Select

    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
    Range("C5:D10").Select

    Application.ScreenUpdating = True

    End Sub

  12. #12
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running A Macro When Any Validation List Item is Selected

    As a test, try this and see if the msgbox pops up when you change the DV list.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    yes...the box opens up and says triggered

  14. #14
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    I figured it out from your code...I changed it to this and it works! Thanks for all your help!

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) = "C5" Then
    If Target.Value <> "" Then Run "UpdateDMReport"
    End If
    End Sub

  15. #15
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Running A Macro When Any Validation List Item is Selected

    Quote Originally Posted by Pony08 View Post
    yes...the box opens up and says triggered
    This should work. I'm stumped as well.

    Please Login or Register  to view this content.
    Is UpdateDMReport in a standard code module e.g. Module1?

    Also, for future reference, surround your pasted code with CODE tags.
    Last edited by AlphaFrog; 03-21-2014 at 11:06 AM.

  16. #16
    Registered User
    Join Date
    07-31-2013
    Location
    Gilbert, AZ
    MS-Off Ver
    Excel 2016
    Posts
    65

    Re: Running A Macro When Any Validation List Item is Selected

    I changed call to run and it worked!

+ 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. Remove an item from a validation list after selected?
    By hey_ray in forum Excel General
    Replies: 6
    Last Post: 02-23-2014, 05:18 PM
  2. Run macro when item from drop-down list is selected
    By barnett2000 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-09-2013, 12:52 PM
  3. macro to unhide row when a dropdown list item is selected
    By ahng in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2012, 07:17 AM
  4. Excel: show a detail of the selected item from a validation list on another cell?
    By danmatley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-06-2011, 06:57 AM
  5. [SOLVED] Running a macro for each item in an Autofilter list
    By Andrew in forum Excel General
    Replies: 1
    Last Post: 08-19-2005, 10:05 AM

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