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
 

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Watch MrExcel Video

Forum statistics

Threads
1,109,367
Messages
5,528,271
Members
409,813
Latest member
robyrux

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top