• 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.

Macro filtering a pivot by month

Cele

Member
Can you please help me with the macro called Confirm_This_Month()

I want to be able to have it confirm the entries for the current month we are in, automatically, without having me to have manually fix the macro every month, please help.

Thank you



Cele
 

Attachments

  • Template_Latest Renewals Report.xlsm
    583.7 KB · Views: 3
I'm not sure if I completely understand what you are trying to accomplish here...

But try this code.
Code:
Sub Confirm_This_Month()
Dim pItem As PivotItem
    With Sheets("Pivotcurrentyr").PivotTables("confirmedthismon").PivotFields( _
        "Month (confirmed)")
        On Error Resume Next
        For Each pItem In .PivotItems
            If Not pItem.Visible Then pItem.Visible = True
        Next
        For Each pItem In .PivotItems
            If pItem.Value = "" Then pItem.Visible = False
            If CDate(pItem.Value) <> DateSerial(Year(Date), Month(Date), 1) Then
                pItem.Visible = False
            Else
                pItem.Visible = True
            End If
        Next
    End With
    ThisWorkbook.Sheets("Pivotprioryr").Visible = False
    ThisWorkbook.Sheets("Pivotcurrentyr").Visible = False
    ThisWorkbook.Sheets("refreshallpivots").Visible = False

    ActiveWorkbook.Worksheets(2).Activate
End Sub

Edit: If you want just the current month. Then change ">" operator to "<>".
Code:
If CDate(pItem.Value) <> DateSerial(Year(Date), Month(Date), 1) Then

Edit2: Code updated to include additional loop to avoid no item visible error.
 
Last edited:
Back
Top