Need Experts help to speed up the code execution

norulen

Active Member
Joined
Nov 30, 2012
Messages
389
Hey Experts,

I have written one code which basically generates the expense analysis of the expenses incurred during the month.

This code is working perfectly fine but it slow than my expectation. Is there any way to speed up that

I will explain the logics of the code and what its designed to do:
I have a pivot table in Sheet with name "Expense Analysis" with Pivot Table named "PivotTable2"
Once the Month has been entered in the combobox used in the userfrom. Pivot table gets refreshed and clears the pivot cache to exclude items which no longer exists.
I want to select all the expense categories which are part of the pivot once its refresed (There could be new categories been added everyday) except two Fund transfer and where the expense category is blank.
In the end expense catergory is sorted as A to Z

Code:
Private Sub CommandButtonGenerate_Click()
  
Sheets("Expense Analysis").Select
Dim Pvt As PivotTable
Dim Pf As PivotField
Dim Pi As PivotItem
Set Pvt = ActiveSheet.PivotTables("PivotTable2")
Set Pf = Pvt.PivotFields("Expense Category")
    Range("B3").Select
    Pvt.PivotCache.MissingItemsLimit = xlMissingItemsNone
    Pvt.PivotCache.Refresh
        
  Pvt.PivotFields("Month").CurrentPage = Me.ComboBoxMonth.Value
     
    With Pf
        For Each Pi In .PivotItems
        On Error Resume Next
             Pi.Visible = True
        On Error GoTo 0
        Next Pi
          
          .PivotItems("Fund Transfer").Visible = False
          .PivotItems("(blank)").Visible = False
    End With
        
        Pf. _
        AutoSort xlAscending, "Expense Category"
        
   Unload Me
   
End Sub

Forgot to mention two important things i guess
1. i am using Excel 2010
2. and the layout of pivot table is that if first filters data according to the month and then throws up a pivot table the expenses category wise sum of expenses incurred
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Anyone got any suggestion?

I know its a long post and needs a little patience but any help would be really appreciated guys :)
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

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