Hello All,
I am trying to apply below VBA code to a pivot to filter based on cell range.
But I am getting error 400.
Sub OAL()
Dim filtvalues As Variant
Dim i As Integer, j As Integer
Dim pvt As PivotField
Dim pitm As PivotItem
filtvalues = Sheets("Pivot").Range("A1:A2")
Set pvt = Sheets("Pivot").PivotTables("PT1").PivotFields("[DDS].[Merged].[Merged]")
pvt.ClearAllFilters
For i = 1 To pvt.PivotItems.Count
Set pitm = pvt.PivotItems(i)
pitm.Visible = False
For j = 1 To UBound(filtvalues, 1) - LBound(filtvalues, 1) + 1
If pitm.Name = filtvalues(j, 1) Then
pitm.Visible = True
Exit For
End If
Next j
Next i
End Sub
I recorded the actions to see the system result of multiple selection.
How do I add below highlighted in filtvalues = Sheets("Pivot").Range("A1:A2") of above code.
Range("B7").Select
ActiveSheet.PivotTables("PT1").PivotFields("[DDS].[Merged].[Merged]"). _
VisibleItemsList = Array("[DDS].[Merged].&[BOM-LHR]")
ActiveSheet.PivotTables("PT1").PivotFields("[DDS].[Merged].[Merged]"). _
VisibleItemsList = Array("[DDS].[Merged].&[BOM-LHR]", _
"[DDS].[Merged].&[LHR-BOM]")
Range("B7").Select
End Sub
Regards,
I am trying to apply below VBA code to a pivot to filter based on cell range.
But I am getting error 400.
Sub OAL()
Dim filtvalues As Variant
Dim i As Integer, j As Integer
Dim pvt As PivotField
Dim pitm As PivotItem
filtvalues = Sheets("Pivot").Range("A1:A2")
Set pvt = Sheets("Pivot").PivotTables("PT1").PivotFields("[DDS].[Merged].[Merged]")
pvt.ClearAllFilters
For i = 1 To pvt.PivotItems.Count
Set pitm = pvt.PivotItems(i)
pitm.Visible = False
For j = 1 To UBound(filtvalues, 1) - LBound(filtvalues, 1) + 1
If pitm.Name = filtvalues(j, 1) Then
pitm.Visible = True
Exit For
End If
Next j
Next i
End Sub
I recorded the actions to see the system result of multiple selection.
How do I add below highlighted in filtvalues = Sheets("Pivot").Range("A1:A2") of above code.
Range("B7").Select
ActiveSheet.PivotTables("PT1").PivotFields("[DDS].[Merged].[Merged]"). _
VisibleItemsList = Array("[DDS].[Merged].&[BOM-LHR]")
ActiveSheet.PivotTables("PT1").PivotFields("[DDS].[Merged].[Merged]"). _
VisibleItemsList = Array("[DDS].[Merged].&[BOM-LHR]", _
"[DDS].[Merged].&[LHR-BOM]")
Range("B7").Select
End Sub
Regards,