T
taych
Hi all,
My codes belows take more than 2 minutes to run the file. I believe
with better codes it will run faster. Appreciate any advise or
suggestion.
Sub DebtorMaster()
On Error Resume Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
Range("A7").Select
Selection.RemoveSubtotal
Range("A4").Select
Range("SalesData.xls!Sales").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("A3:I4"), CopyToRange:=Range("A6:K6"),
Unique:=False
Range("A4:I4").Copy
Range("A7").Select
Workbooks.Open Filename:="C:\My Documents\Master.xls"
Sheets("Sheet2").Range("A2").Select
ActiveSheet.Paste
Range("A2").Select
Application.Run "Master.xls!Masterlist"
Range("'Master.xls'!Masteroutput").Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Windows("SalesData.xls").Activate
Range("A7").Select
Selection.End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
Range("A7").Select
Selection.Sort Key1:=Range("E7"), Order1:=xlAscending,
Key2:=Range("F7") _
, Order2:=xlAscending, Key3:=Range("C7"), Order3:=xlAscending, Header:=
_
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=5, Function:=xlSum, TotalList:=Array(7, 8,
9), _
Replace:=True, PageBreaks:=True, SummaryBelowData:=True
Selection.AutoFormat Format:=xlRangeAutoFormatSimple
Dim lastrow As String
lastrow = ActiveSheet.Range("E65536").End(xlUp).Row
ActiveSheet.PageSetup.PrintArea = "$A$7:$K$" & lastrow
CreateObject("WScript.Shell").Popup "Please preview the page setting is
correct," + Chr(10) & "then click PRINT to print the Debtors List", 10,
"Printing"
End Sub
My codes belows take more than 2 minutes to run the file. I believe
with better codes it will run faster. Appreciate any advise or
suggestion.
Sub DebtorMaster()
On Error Resume Next
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
Range("A7").Select
Selection.RemoveSubtotal
Range("A4").Select
Range("SalesData.xls!Sales").AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Range("A3:I4"), CopyToRange:=Range("A6:K6"),
Unique:=False
Range("A4:I4").Copy
Range("A7").Select
Workbooks.Open Filename:="C:\My Documents\Master.xls"
Sheets("Sheet2").Range("A2").Select
ActiveSheet.Paste
Range("A2").Select
Application.Run "Master.xls!Masterlist"
Range("'Master.xls'!Masteroutput").Select
Selection.Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Windows("SalesData.xls").Activate
Range("A7").Select
Selection.End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
Range("A7").Select
Selection.Sort Key1:=Range("E7"), Order1:=xlAscending,
Key2:=Range("F7") _
, Order2:=xlAscending, Key3:=Range("C7"), Order3:=xlAscending, Header:=
_
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=5, Function:=xlSum, TotalList:=Array(7, 8,
9), _
Replace:=True, PageBreaks:=True, SummaryBelowData:=True
Selection.AutoFormat Format:=xlRangeAutoFormatSimple
Dim lastrow As String
lastrow = ActiveSheet.Range("E65536").End(xlUp).Row
ActiveSheet.PageSetup.PrintArea = "$A$7:$K$" & lastrow
CreateObject("WScript.Shell").Popup "Please preview the page setting is
correct," + Chr(10) & "then click PRINT to print the Debtors List", 10,
"Printing"
End Sub