Filter negative numbers from pivot using macro

sumeetp

New Member
Joined
May 13, 2012
Messages
6
Hello,
I have a pivot with a filter with many numbers positive and negative value and i want a macro to filter then and check the negative value
i tried modifying the code here but not getting it.

Code:
Sheets("Tables").Select
Dim varItemList() As Variant
    Dim pviItem As PivotItem
    Dim i As Integer
    Application.ScreenUpdating = False
     varItemList = Array(-300)
     varItemList2 = Array(-1)
     ' Loop through each item and compare the caption to the data in the array
    For Each pviItem In Sheets("Tables").PivotTables("PivotTable2").PivotFields("TS").PivotItems
        pviItem.Visible = True
        For i = LBound(varItemList) To UBound(varItemList2)
            If pviItem.Caption = varItemList(i) Then
                pviItem.Visible = True
            End If
        Next i
        DoEvents
    Next pviItem
    Application.ScreenUpdating = True
    
Sheets("Main Page").Select
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Rather than using the checkbox filtering have you tried using Value Filters (above the checkboxes, in the same filtering dropdown) and setting to Greater Than or Equal to 0?
 
Upvote 0
Yes i was going for the same but the filter is "TS" and the column first data is Persons name and it is not possible to filter positive data from the data.So i planned on using a macro to uncheck the data in the TS filter.Is there anyway that we can correct this code to uncheck the negative integer and check the positive integer.
 
Upvote 0
Code:
Sheets("Tables").Select
Dim varItemList1() As Variant
    Dim pviItem1 As PivotItem
    Dim a As Integer
    Application.ScreenUpdating = False
    varItemList1 = Array("IN", "IP", "MN")
    ' Loop through each item and compare the caption to the data in the array
    For Each pviItem1 In Sheets("Tables").PivotTables("PivotTable1").PivotFields("Status").PivotItems
            pviItem1.Visible = False
        For a = LBound(varItemList1) To UBound(varItemList1)
            If pviItem1.Caption = varItemList1(a) Then
                pviItem1.Visible = True
            End If
        Next a
        DoEvents
    Next pviItem1
    Application.ScreenUpdating = True
    
Sheets("Main Page").Select

The above code is working now what i want to do is check all the negative array and uncheck them.
for eg: varItemList1 = Array(-800 to -1)
But it is giving me a debug error.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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