VBA: Filter pivot table based on multiple time ranges

FunsizedNerd

New Member
Joined
Mar 20, 2019
Messages
17
Want to filter pivot table times based on whether a cell value (next to each hour period in a day) is true or false i.e. have 24 hourly time periods, so 24 cells with a T/F value.

Got it to a point where it filters the pivot table based on one time period e.g. between 0600 and 0659 but have yet to manage multiple ranges (these might not follow each other directly e.g. could be 0100 to 0159 and 0700 to 0759, omitting values between 0200 and 0659)

Code:
For Each cell_ In myrange
If cell_.Value = True Then
cell_value1 = cell_.Offset(0, 2).Value
cell_value2 = cell_.Offset(0, 3).Value

With pf1.PivotFilters
Do While .Count > 0
.Item(1).Delete
Loop
.Add2 xlDateBetween, Value1:=cell_value1, Value2:=cell_value2
End With
End If
Next
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,215,744
Messages
6,126,623
Members
449,322
Latest member
Ricardo Souza

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