VBA Code to update pivot table filter is not working

morky11

New Member
Joined
Feb 16, 2010
Messages
9
Hi
I have code to update pivot tables based on a cell value. The user selects a filter on a 'Dashboard' tab via ranges plstMonths and plstDepts and a dropdown selection resulting in selYear. The choices are copied to a cell on my 'Calculations' tab via:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Application.Intersect(ActiveCell, [plstMonths]) Is Nothing Then
        [selMonth] = ActiveCell.Value
    Call updatePivot
    ElseIf Not Application.Intersect(ActiveCell, [plstDepts]) Is Nothing Then
        [selDept] = ActiveCell.Value
    Call updatePivot
    End If
End Sub

Macro 'updatePivot' updates the filter pivots with the results in valYear, selMonth and selDept

Code:
Sub updatePivot()
    'refresh pivot tables
    ThisWorkbook.RefreshAll
    'Update filters
    [fltCALateOYear] = [valYear]
    [fltEquipOYear] = [valYear]
    [fltERLateOYear] = [valYear]
    [fltProductOYear] = [valYear]
    [fltRCAOYear] = [valYear]
    [fltRoomOYear] = [valYear]
    [fltUtilOYear] = [valYear]
    [fltEquipOYear] = [valYear]
    
    [fltCALateOMonth] = [selMonth]
    [fltEquipOMonth] = [selMonth]
    [fltERLateOMonth] = [selMonth]
    [fltProductOMonth] = [selMonth]
    [fltRCAOMonth] = [selMonth]
    [fltRoomOMonth] = [selMonth]
    [fltUtilOMonth] = [selMonth]
    [fltEquipOMonth] = [selMonth]
    
    [fltCALateDept] = [selDept]
    [fltEquipDept] = [selDept]
    [fltERLateDept] = [selDept]
    [fltProductDept] = [selDept]
    [fltRCADept] = [selDept]
    [fltRoomDept] = [selDept]
    [fltUtilDept] = [selDept]
    [fltEquipDept] = [selDept]


End Sub

Here's my problem: everything works fine, except for the (All) selection on selDept. When (All) is selected as the department, the table fails to update. Refreshing the table manually reverts the filter to the first available selection in the filter options (in this case Engineering). I am able to manually select the (All) filter and selection of individual departments works fine, just not for (All) departments.

The (All) selection appears to be working for selMonth, just not selDept.

It's driving me crazy. Any ideas?

Thanks in advance
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top