Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2018, 07:43 PM
Levi92 Levi92 is offline [VBA] Filter Pivot Table by dates Windows 10 [VBA] Filter Pivot Table by dates Office 2016
Novice
[VBA] Filter Pivot Table by dates
 
Join Date: Oct 2018
Posts: 4
Levi92 is on a distinguished road
Default [VBA] Filter Pivot Table by dates

I am currently building an application with Excel and would like to add a feature whereby the user can filter a pivot table by simply choosing the date via a user form. Technically speaking, everything works just fine. But here is my problem:

The filter is applied to the pivot table, but the pivot table is blank.





If I go into the filter settings, you can see that VBA correctly enters the dates.

[IMG]www.msofficeforums.com/attachment.php?attachmentid=12893&stc=1&d=15422496 48[/IMG]

Edit: Somehow this picture won't load. Check out the attached file!

If I manually press OK now, the filters are applied successfully:



Here is my VBA Code:

Code:
Sub ApplyDates()

Dim FromDate As Date, ToDate As Date
Dim pvtFilters As PivotFilter

Set wb = ThisWorkbook
Set ws1 = wb.Worksheets(1)
Set wsStaging = wb.Worksheets("Staging_Sheet")

FromDate = Format(wsStaging.Range("FromDate").Value, "MM/DD/YYYY")
ToDate = Format(wsStaging.Range("ToDate").Value, "MM/DD/YYYY")

For Each pvt In ws1.PivotTables
    With pvt
        .ClearAllFilters
        .PivotFields("[Orders].[Day (Value)].[Day (Value)]") _
        .PivotFilters.Add2 Type:=xlCaptionIsBetween, Value1:=FromDate, Value2:=ToDate
    End With
Next

End Sub
Does anyone have an idea how to solve this issue? To me it looks like pivot tables cannot be filtered with VBA
Attached Images
File Type: jpg 02.jpg (43.1 KB, 17 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to filter between two dates in MS Query criteria when the dates are text ("20180903", etc.) kingmb Excel 2 09-11-2018 01:08 AM
[VBA] Filter Pivot Table by dates Grouping Dates in Pivot Table Dana-H Excel 1 02-23-2017 12:20 AM
[VBA] Filter Pivot Table by dates Pivot table dates issue salse Excel 1 06-08-2016 12:23 PM
[VBA] Filter Pivot Table by dates Filter 2 columns between 2 dates s_samira_21 Excel 2 02-08-2015 10:34 PM
[VBA] Filter Pivot Table by dates Grouping Dates in Excel Pivot Table mskennedy Excel 2 02-27-2013 11:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft