VBA Select Case problem with dates in Pivot table

I am having trouble getting a Select Case statement to:
'Select all "Wk THURSDAY" dates in Month of Report date, and hide the rest
The code doesn't work as intended.

It goes to "case else" for every date in pivot table, when it should go to one of the other "case pi.value" options when the the month and year of the date being considered are the month and year of report date. The report date ("dt" in code) is 11/02/2010 (UK) or 02/11/2010 (US).
No error message is displayed.

There is one pivot table on my worksheet.
An xls file of a copy of the pivot table (values and formats only), and the vba code of the slect case statement is attached.
Please help. Thank you.
'Select all "Wk THURSDAY" dates in Month of Report date, and hide the rest
    For Each pt In ActiveSheet.PivotTables
        For Each pf In pt.RowFields
            For Each pi In pf.PivotItems
                Select Case pi.Value
                    Case pi.Value Like Month(dt) & "/*" & "*/" & Year(dt)
                        pi.Visible = True
                    Case pi.Value Like Month(dt) & "/*" & "/" & Year(dt)
                        pi.Visible = True
                    Case Else
                        pi.Visible = False
                End Select
            Next pi
        Next pf
    Next pt

Open in new window

VBA-Case-question---Ex.-Exchange.xls
LVL 1
dev00790Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Why not simply test on month and year directly?  Replace:

                Select Case pi.Value
                    Case pi.Value Like Month(dt) & "/*" & "*/" & Year(dt)
                        pi.Visible = True
                    Case pi.Value Like Month(dt) & "/*" & "/" & Year(dt)
                        pi.Visible = True
                    Case Else
                        pi.Visible = False
                End Select

with:

                pi.Visible = (Month(pi.Value) = Month(dt) And Year(pi.Value) = Year(dt))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dev00790Author Commented:
Brilliant! Thanks a lot. :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.