Performance issue VB

Alex B

New Member
Joined
Jan 22, 2015
Messages
12
Hi,

I´m trying to filter out unique names based on chosen year and organizational unit from a list that contains approx 20000 rows.

Use code below, which is executed with a control button. I experience performance issues, the macro takes 5-10 sec to run.
Is there any better way to do it?

Code:
Sub filter()



    Application.ScreenUpdating = False
        
    Sheets("Resurstid").Visible = True
        
    Sheets("Resurstid").Select
    Columns("A:F").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Range( _
        "H1:M2"), CopyToRange:=Range("H4"), Unique:=True
        
    Sheets("Analys per konsult").Select
    
                With Sheets("Analys per konsult")


            With .Range("B15:N1000")
            .Clear
            End With
            Dim lastRow2 As Long
            lastRow2 = Sheets("Resurstid").Range("H" & Rows.Count).End(xlUp).Row + 7
            Sheets("Analys per konsult").Range("B13:N13").AutoFill Destination:=Sheets("Analys per konsult").Range("B13:N" & lastRow2)
            End With
    
    Sheets("Resurstid").Visible = False
        
End Sub
 
Slightly... What I experience in general is that when org.units with up to 20-50 names are chosen, the code runs quite ok.
It´s with larger org.units (+100 names) it starts to lag.
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I expect it's related to the number of formulas and their complexity. But you haven't told me what the formulas are so it's difficult to help further.
 
Upvote 0
Here is an example:

=IF(Vald_månad>12;IF(ISERROR(SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;Uppdragsgrupp;"Externa uppdrag";År_tid;Innevarande_år;Månad_tid;">="&MinMånad;Månad_tid;"<="&MaxMånad)/SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;År_tid;Innevarande_år;Månad_tid;">="&MinMånad;Månad_tid;"<="&MaxMånad));"";SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;Uppdragsgrupp;"Externa uppdrag";År_tid;Innevarande_år;Månad_tid;">="&MinMånad;Månad_tid;"<="&MaxMånad)/SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;År_tid;Innevarande_år;Månad_tid;">="&MinMånad;Månad_tid;"<="&MaxMånad));IF(ISERROR(SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;Uppdragsgrupp;"Externa uppdrag";År_tid;Innevarande_år;Månad_tid;Vald_månad)/SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;År_tid;Innevarande_år;Månad_tid;Vald_månad));"";SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;Uppdragsgrupp;"Externa uppdrag";År_tid;Innevarande_år;Månad_tid;Vald_månad)/SUMIFS(Timmar_tid;Resurs_tid;'Analys per konsult'!B13;År_tid;Innevarande_år;Månad_tid;Vald_månad)))

Fomulas use Named cells and ranges, though in swedish, so I think that they won't help you much. And as you can see above, it's quite long so maybe calculating this and similar formulas in some 1000-2000 cells do take some time...
 
Upvote 0
Since you are using SUMIFS you must have Excel 2007 or above, in which case you can use IFERROR instead of IF(ISERROR to avoid having the formula twice. The syntax for:

=IF(ISERROR(Formula),"",Formula)

is:

=IFERROR(Formula,"")
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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