You can use AutoFilter to do most of the work you're doing in your CommandButton2 macro and significantly increase the speed by not looping through the whole dataset over and over again.
For instance, this is how I would write section #9, it leaves the FILLER rows hidden after painting them white...is this what you had in mind?:
'======================================================
'9) White text for filler rows, hide rows
'======================================================
lngRow = Range("I4").End(xlDown).Row
Range("A4:I4").AutoFilter
Range("A4:I4").AutoFilter Field:=1, Criteria1:="Filler"
Range("A5:I" & lngRow).SpecialCells(xlCellTypeVisible).Font.ColorIndex = 2
Range("A4:I4").AutoFilter Field:=1, Criteria1:="<>Filler"
Section 8 really only needs to find the one Grand Total cell, right? NO need to loop the entire sheet for that, just go to it directly:
'======================================================
'8) Shades Grand Total column Dark Gray
'======================================================
lngRow = Columns("F").Find("Grand Total", , xlValues, xlPart).Row
Range(Cells(lngRow, 1), Cells(lngRow, 9)).Interior.ColorIndex = 16
You tend to manually select things before applying your actions. That's only required if you're human, VBA can act on cells/ranges directly without selecting them first...at all. Sections 5 & 6 demonstrate this:
'======================================================
'5) Sorts data by PO#
'======================================================
On Error GoTo Error_Chk
Range("A4", Range("J4").End(xlDown)).Sort Key1:=Range("E5"), Order1:=xlAscending, Key2:=Range("F5") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
'======================================================
'6) Creates Sub Totals
'======================================================
Range("A4", Range("J4").End(xlDown)).Subtotal GroupBy:=6, Function:=xlSum, TotalList:=Array(9), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
I would rewrite the whole FILLER macro without all the selecting and FillDown stuff:
Sub FILLER()
Application.ScreenUpdating = False
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Temp Sheet"
Range("A1:A16") = "Filler"
Range("D1") = "SU"
Range("D2") = "MP"
Range("D3") = "MH"
Range("D4") = "OC"
Range("D1:D4").Copy Range("D5:D16")
Range("E1:E16").NumberFormat = "@"
Range("E1:E4") = "01"
Range("E5:E8") = "02"
Range("E9:E12") = "04"
Range("E13:E16") = "09"
Range("I1:I16") = 0
Range("A1:I16").Copy
Sheets("Accrual Sheet").Activate
Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues, _
Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Range("A5", Range("I5").End(xlDown)).Sort Key1:=Range("A5"), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
Bookmarks