• 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 code shortening

ManuGrim

New Member
Hello,

I have the following macros assigned to buttons.
Can someone please help me to make the Daily macro load faster and not require such a long time to run?
Also how can I shorten the code for the different ranges?
I already tried the following but it does not work.

Range("D9:D374,D374:D739").AdvancedFilter Action:=xlFilterInPlace, Unique:=True

Code:
Sub Daily()

'Daily Macro
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.Calculation = xlManual
   
    Range("D9:D739").AdvancedFilter Action:=xlFilterInPlace, Unique:=False
   
    Application.Calculation = xlAutomatic
    Application.ScreenUpdating = True
    Application.EnableEvents = True
   
End Sub

Sub Weekly()

' Weekly Macro
    Range("D9:D374").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("D374:D739").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("D739:D1105").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("D1105:D1470").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("D1470:D1835").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
End Sub

Sub Monthly()

' Monthly Macro
    Range("e9:e374").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("e374:e739").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("e739:e1105").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("e1105:e1470").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("e1470:e1835").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
End Sub

Sub Quarterly()

'Quarterly Macro
    Range("f9:f374").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("f374:f739").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("f739:f1105").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("f1105:f1470").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    Range("f1470:f1835").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
End Sub

Thank you :)
 
What exactly does the Daily macro do? You call an AdvancedFilter, but it's not being copied, there's no criteria, and it's not unique...when I run it, nothing happens. No idea why this would be taking a long time. My guess would be more that you have a lot of formulas, probably volatile ones?

For the different ranges, should they all get filtered at same time? Perhaps if you explain what the actual goal is, that might help decipher the code. As is, it looks like all the Weekly/Monthly/Quarterly macros are the same line, just a different range. You could make it that user selects the range and then runs a single macro....but again, not sure about your actual layout.
 
Here is an example. But here is just the one of many sheets of a workbook. It moves ok now that the sheet is alone...but when I have other sheets with graphs and stuff, it loads very slow.

Thanks
 

Attachments

  • Daily-Mth-Qtrly-V1.xlsm
    108.6 KB · Views: 3
Here's one quick way to speed things up a little, and make editing the code easier. Looks like an interesting task. I take it you are trying to build labels for a chart?
 

Attachments

  • Daily-Mth-Qtrly-Faster.xlsm
    121.6 KB · Views: 7
Back
Top