VBA Auto Filter Multiple Values in a PivotTable

bshglobal

New Member
Joined
Aug 12, 2015
Messages
1
Hi there! First time posting here, you all have been amazing help while building out multiple projects. Really appreciate the community.

I currently have two Pivot tables [PivotTable1 and PivotTable2] on a sheet("PivotTable"). I Have two Filters for each, one is Auditor, the other is Date.

Question 1: I am trying to limit the selection of the Date Filter in PivotTable1 to only allow people to select one date, not multiple. Is this something that can be done?

Question 2: I have a Name_Range called PivotFilterDate which takes the selected date in the PivotTable1 Date Filter (ie:8/12/2015) and automatically lists out the dates in that selected month in a column (ie:8/1/2015,8/2/2015,8/3/2015,etc.). I would like to AutoFilter with VBA PivotTable2's Date Filter with those dates in that Name_Range.

Here is the code I am currently using
----------------------------------------------
Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range
Dim rang As Range
Dim rangle As Range

Set rng = Me.Range("AuditorFilter")
Set rang = Me.Range("PivotFilterDate")
Set rangle = Me.Range("datefilter")

If Not Application.Intersect(Target, rng) Is Nothing Then
With Sheets("PivotTable").PivotTables("PivotTable1").PivotFields("Auditor")
.ClearAllFilters
If Len(rng.Value) > 0 Then .CurrentPage = rng.Value
End With
End If

If Not Application.Intersect(Target, rng) Is Nothing Then
With Sheets("PivotTable").PivotTables("PivotTable2").PivotFields("Auditor")
.ClearAllFilters
If Len(rng.Value) > 0 Then .CurrentPage = rng.Value
End With
End If

If Not Application.Intersect(Target, rangle) Is Nothing Then
With Sheets("PivotTable").PivotTables("PivotTable2").PivotFields("Date")
.ClearAllFilters
If Len(rangle.Value) > 0 Then .CurrentPage = rang.Value
End With
End If

If MsgBox("Make sure to Click the button Update Daily/Weekly Lists before printing a PDF", vbOKOnly) = vbOK Then
Else: End If

End Sub
--------------------------------------------------------
(FYI: This Code also refers to another named range that updates the two pivot tables with a selected Auditor from a drop down list. This works magically)

Unfortunately it keeps selecting the first date in the list (which in this case is 8/1/2015), not any of the others in the range. It appears that the code only allows one item to pass thru the filter, not a list.

Please help? 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,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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