• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Filter Reserved character from Pivot table

Danny

Member
Hi People

Quick question; I currently have some VBA code that filters out results in my pivot table that contain key words. This has worked correctly (which is nice). I am using:

Code:
AciveSheet.PivotTables("PivotTable2").PivotFields("Project Name"). _
        PivotFilters.Add Type:=xlCaptionDoesNotBeginWith, Value1:="MC"

However, in my pivot table i have words starting with "MC" (including the the speech marks).

This means my filter code would need to read:

Code:
        PivotFilters.Add Type:=xlCaptionDoesNotBeginWith, Value1:=""MC""

But this does not work. Is there a way to filter for reserved characters? I know in Java there is but this is the first time I have come across this in VBA.

Thanks in advance
Danny
 
Last edited:
Hi SirJB7 and Crochsw

Thank you for your answers, both are correct and work as expected, much appreciated.

My filter works correctly when I want to filter for 1 think only, IE: filter words that start with MC

However when I want to to filter for two things IE: filter words that start with MC and "MC" I get an error.

Duplicating what below and changing the value returns a "1004 run time error, Application defined or object defined error"

Code:
ActiveSheet.PivotTables("PivotTable2").PivotFields("Project Name"). _
        PivotFilters.Add Type:=xlCaptionDoesNotBeginWith, Value1:=Chr(34) & "MC" & Chr(34)

Any advice would be much appreciated

Thank you once again
Danny
 
Hi, Danny!
Could you post a sample file or at least the list of the related cell values? Please indicate a few or all the criteria which you'd want the information to be filtered by.
Regards!
 
Back
Top