Share via

vbscript syntax pivotfilters

Anonymous
2012-03-09T15:26:18+00:00

I'm having difficulty translating the syntax from a VBA macro to VBScript for a Pivot Table Filter.  The following is the VBA code generated from the macro.

ActiveSheet.PivotTables("PivotTable1").PivotFields("Finish Date").PivotFilters. _

        Add Type:=xlDateBetween, Value1:="3/10/2012", Value2:="3/16/2012"

VBScript...something like?

Const xlDateBetween = 35

objWorksheet.PivotTables("PivotTable1").PivotFields("Finish Date").PivotFilters.Add = xlDateBetween,"1/19/2012","1/19/2012"

Frustrating getting syntax right..

Thanks.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-03-09T15:59:08+00:00

= xlDateBetween

should be

 xlDateBetween

Since it is just an argument list you do not want the equal sign. Just a blank space between Add and the list.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Anonymous
2012-03-09T16:43:44+00:00

Got it...based on the "argument" breadcrumb, that led me to look more carefully at the PivotFilters Add Method.  The list of parameters is not quite the same as the VBA code generated.  I needed to add the field name of the filter too.  Thanks again.

fdate = "01/19/2012"

tdate = "01/19/2012"

filter1 = "Finish Date"

objWorksheet.PivotTables("PivotTable1").PivotFields("Finish Date").PivotFilters.Add xlDateBetween, filter1, fdate, tdate

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-03-09T16:21:18+00:00

    = xlDateBetween

    should be

     xlDateBetween

    Since it is just an argument list you do not want the equal sign. Just a blank space between Add and the list.

    Thanks for the assist Jim, looks like that got me past the syntax issue now I'm on to "Invalid procedure call or arguement" looking at the object Method I see there are other parameters, but they are all optional, so I don't think that is it.  I'm usually good hacking these out, but this one just seems more confusing for some reason.  Appreciate your help.

    objWorksheet.PivotTables("PivotTable1").PivotFields("Finish Date").PivotFilters.Add xlDateBetween,"1/19/2012","1/19/2012"

    Was this answer helpful?

    0 comments No comments