My subtotal macro is taking forever

CausticOne

New Member
Joined
Sep 9, 2011
Messages
2
I've got a sheet with about 1000 rows and I am performing the following function on it

Code:
Sub createSubtotals()
    Dim subtotal_groupby As Variant, subtotal_columns As Variant, format_subtotal_pagebreak As Variant

    format_subtotal_pagebreak = True

    subtotal_groupby = 2
    subtotal_columns = Array(6, 7, 8, 9, 10, 11, 12, 13, 14, 15)

    With Sheets(1)
        .Cells.Subtotal GroupBy:=subtotal_groupby, Function:=xlSum, TotalList:=subtotal_columns, _
        Replace:=True, PageBreaks:=format_subtotal_pagebreak, SummaryBelowData:=True
        .Outline.ShowLevels rowLevels:=2
        .Cells.SpecialCells(xlCellTypeVisible).Font.Bold = True
            Outline.ShowLevels rowLevels:=3
    End With
End Sub

Problem is it is taking a long, long time to actually complete. Is there a quicker way to do the same thing? I've tried inserting screenupdating=false and calculation=manual comments to speed things up, but gains are minimal. I need something a bit more fundamental.

Thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What happens if you change page breaks to False?
 
Upvote 0
If you change back to True it's going to slow the code down again.

I'm sure there are other ways to deal with the printing/page setup.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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