+ Reply to Thread
Results 1 to 5 of 5

Combining two Events

  1. #1
    Registered User
    Join Date
    11-28-2020
    Location
    Costa Rica
    MS-Off Ver
    2016
    Posts
    2

    Combining two Events

    Hello,

    Can someone help me combine the codes below into a single event?. I'm trying to control two pivot table filters, Agent and Month based on two separate ranges D6:E6 and D7:E7 . I was able to get a macro to work in one of the ranges but I have no idea on how to include both in the same code.

    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim xPTable As PivotTable
    Dim xPFile As PivotField
    Dim xStr As String
    On Error Resume Next
    If Intersect(Target, Range("D6:E6")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Set xPTable = Worksheets("Scorecard").PivotTables("ScoreCard_1")
    Set xPFile = xPTable.PivotFields("Agent")
    xStr = Target.Text
    xPFile.ClearAllFilters
    xPFile.CurrentPage = xStr
    Application.ScreenUpdating = True

    End Sub

    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim xPTable As PivotTable
    Dim xPFile As PivotField
    Dim xStr As String
    On Error Resume Next
    If Intersect(Target, Range("D7:E7")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Set xPTable = Worksheets("Scorecard").PivotTables("ScoreCard_1")
    Set xPFile = xPTable.PivotFields("Month")
    xStr = Target.Text
    xPFile.ClearAllFilters
    xPFile.CurrentPage = xStr
    Application.ScreenUpdating = True

    End Sub

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Combining two Events

    See if this works for you.

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

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

    Re: Combining two Events

    Try this.
    Please Login or Register  to view this content.
    Last edited by Norie; 11-28-2020 at 02:09 PM.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    11-28-2020
    Location
    Costa Rica
    MS-Off Ver
    2016
    Posts
    2

    Re: Combining two Events

    This did exactly what I needed. Thank you for you help!

    Quote Originally Posted by JLGWhiz View Post
    See if this works for you.

    Please Login or Register  to view this content.
    Last edited by Blaxz; 11-28-2020 at 01:17 PM.

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Combining two Events

    Quote Originally Posted by Blaxz View Post
    This did exactly what I needed. Thank you for you help!
    You're welcome,
    Regards, JLG

+ 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] Combining two Worksheet_SelectionChange Events help!
    By tabbytomo in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-29-2016, 07:54 AM
  2. Combining two worksheet change events
    By djfergie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-14-2013, 11:07 AM
  3. Combining two Worksheet_Change Events
    By Fett2oo5 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-09-2013, 01:05 PM
  4. [SOLVED] Combining two opening events when file is opened
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-05-2013, 03:28 PM
  5. Need help combining multiple Worksheet_Change events
    By rlbush2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2012, 04:51 PM
  6. [SOLVED] Combining Two Change Events
    By computerdan in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-25-2012, 02:00 AM
  7. Combining object (textbox and combobox) change events
    By abousetta in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-11-2011, 10:44 PM

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