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
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