Pivot Table filters via VBA giving 1004 error

JST013

Board Regular
Joined
Mar 11, 2015
Messages
74
Happy holidays MR.Excel users!

I've hit a little snag in filtering this pivot table report. I marked in red my problem area.. not sure why but it is giving me different errors depending on the date format but either way it does not work. Any suggestions on how to make it work? My latest trial i used format "Short Date" and it gave me 1004 runtime error. Everything works up until that point. The textboxes are on a userform if that changes anything, and I am using excel 2013.

Code:
    starr = Format(Me.tbStartDate.Text, "Short Date")
    endd = Format(Me.tbEndDate.Text, "Short Date")


    For Each ws In wbReport.Sheets
        For Each pt In ws.PivotTables
            For Each pi In pt.PivotFields("People").PivotItems
                If pi.Name <> person Then
                    pi.Visible = False
                ElseIf pi.Name = person Then
                    pi.Visible = True
                End If
            Next pi
[COLOR=#ff0000]            pt.PivotFields("Date").PivotFilters.Add2 Type:=xlDateBetween, Value1:=starr, Value2:=endd[/COLOR]
           
        Next pt
    Next ws
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Dryver14,

Thank you for your response, but I don't think so. I created the two variables, starr and endd to represent the date format of whatever the user types into the two text boxes.
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,077
Latest member
Jocksteriom

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