+ Reply to Thread
Results 1 to 6 of 6

Run Macro when slicer selection changes

Hybrid View

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

    Run Macro when slicer selection changes

    What code do in need to run a macro any time the value of a cell changes?
    Last edited by Pony08; 01-05-2016 at 03:26 PM.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Run Macro when slicer selection changes

    You could try something like this perhaps

    Private Sub Worksheet_Change(ByVal Target As Range)
    	If Not Intersect(Range(“YourCellAddress”), Target) Is Nothing Then
    	  Run your macro
    	End If
    End Sub
    Alf

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

    Re: Run Macro when slicer selection changes

    Thx! That works well if I type in a new number...I have a macro that I want to run if a cells that has a formula in it...and the results from the formula changes...I think the fact that the formula stays the same, the macro will not run until I overwrite the formula with just a number.

    Thoughts?

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Run Macro when slicer selection changes

    Well if the change is based on a formula then you could try this:

    Right click on the sheet tab where the cell is you want to capture a change in. Click "View Code" and paste this code in the window. Say it's sheet1

    Private Sub Worksheet_Calculate()
        If Range("B4").Value <> PrevVal Then
          ' Run Macro
        End If
    End Sub
    Then to the left in the Visual Basic Window you see a number of work sheets and "ThisWorkbook".

    Right click on "ThisWorkbook" and paste this code in the new window.

    Private Sub Workbook_Open()
        PrevVal = Sheet1.Range("B4").Value
    End Sub
    Save file and open it again. Now try to update you formula target cell and see if macro runs.

    Alf

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

    Re: Run Macro when slicer selection changes

    That worked great Alf...thanks for all your help!!!

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: Run Macro when slicer selection changes

    You are welcome.

    Thanks for feedback.

    Alf

+ 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 Run when Slicer Selection is Changed (multiple slicers)
    By jcanlas in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-09-2021, 11:41 AM
  2. [SOLVED] Macro to Run when Slicer Selection is Changed
    By MBeedle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-28-2017, 09:29 AM
  3. [SOLVED] Help with VB Code to pass a selection to another workbook's slicer
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-08-2015, 01:11 AM
  4. Have a cell equal to a selection in a slicer?
    By qlikview in forum Excel General
    Replies: 1
    Last Post: 07-07-2015, 03:00 PM
  5. Limiting a pivot table slicer to one selection
    By behrensf84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-14-2014, 09:25 PM
  6. Limiting Slicer multiple selection
    By Paul-NYS in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 12-17-2012, 02:58 PM
  7. Slicer Macro - unfilter another slicer on selection
    By chadheins in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2012, 10:41 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