Auto Filter Pivot Table

Raelnunes

New Member
Hello,
Im trying to autofilter a Excel Pivot Table.
If I run the code in a normal sheet , it works, but when I run the same code to filter a dynamic range I get an error.

I need to filter the column "D" with two criterias

tmEElCbTPGuXijbc1ZsB_Dynamic Range.PNG



This is the code I'm using:

Dim sw, dw As Object
Dim ss, ds As Object
Dim excel, sheet, varUsedRange As Object
Dim FilteredCount as Long

Try

sw = GetWorkbook(handle, workbookname)
ss = GetWorksheet(handle, workbookname, worksheetname)


sw.Activate()
ss.Activate()
excel = ss.Application
sheet = excel.ActiveSheet

varUsedRange = sheet.UsedRange().address

If sheet.AutoFilterMode Then
sheet.AutoFilterMode = False
End If

sheet.range(varUsedRange ).AutoFilter (Field:=4, Criteria1:="=611")

FilteredCount = sheet.AutoFilter.Range.Columns("D").SpecialCells(12).Cells.Count - 1


If FilteredCount > 0 then

End if

Success = True

Catch e As Exception
Success = False
Message = e.Message
Finally
sw = Nothing
ss = Nothing
dw = Nothing
ds = Nothing
excel = Nothing
sheet = Nothing
varUsedRange = Nothing
End Try
 
Last edited:

sahil_raina_91

Active Member
That appears to be a PIVOT table instead of a regular sheet.
AutoFilter will not work on the pivot table.
Please try recording a macro and create a different code for the same.
 
Top